当前位置: 首页 > article >正文

Docker compose启动服务遇到的问题

这是学长留的一个任务,用docker compose启动三个服务,分别是minio、elasticsearch、nginx。
话不多说,让我们看看有哪些错误。

一、数据卷挂载权限问题

这是原始docker-compose.yaml文件

version: "3.8"

networks:
  my-net:
    name: gkynet

services:
  minio:
    image: "bitnami/minio:latest"
    container_name: minio
    ports:
      - "9000:9000"
      - "9001:9001"
    environment:
      - MINIO_ROOT_USER=root
      - MINIO_ROOT_PASSWORD=123456
    volumes:
      - "./minio/data:/bitnami/minio/data"
    networks:
      - my-net
  elasticsearch:
    image: "elasticsearch:7.17.5"
    container_name: es
    environment:
      - "TZ=Asia/Shanghai"
    ports:
      - "9200:9200"
    volumes:
      - "./es/certs:/usr/share/elasticsearch/config/certs"
      - "./es/data:/usr/share/elasticsearch/data"
    networks:
      - my-net
  nginx:
    image: "nginx:latest"
    container_name: nginx
    environment:
      - "TZ=Asia/Shanghai"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "./nginx/html:/usr/share/nginx/html"
    networks:
      - my-net

执行docker compose up -d命令后,三个容器都没有启动成功。
执行docker logs minio查看日志

/opt/bitnami/scripts/libminio.sh: line 364: /bitnami/minio/data/.root_user: Permission denied

其他两个服务的日志也差不多,都是挂载的目录没有正确的权限。

解决办法

使用以下命令设置目录权限:

chmod -R 777 挂载的目录路径

二、Elasticsearch 启动的引导检查失败

es报错信息:

ERROR: [2] bootstrap checks failed. You must address the points described in the following [2] lines before starting Elasticsearch.
bootstrap check failure [1] of [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
bootstrap check failure [2] of [2]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

原因:

  1. max virtual memory areas 的限制过低,需要增加到至少 262144。
  2. 默认的发现设置对于生产环境来说是不合适的,至少需要配置其中一个:discovery.seed_hosts、discovery.seed_providers 或 cluster.initial_master_nodes。

解决办法

使配置es的环境变量:

elasticsearch:
    image: "elasticsearch:7.17.5"
    container_name: es
    environment:
      - "TZ=Asia/Shanghai"
      - "cluster.name=elasticsearch" #设置集群名称为elasticsearch
      - "discovery.type=single-node" #以单一节点模式启动
      - "ES_JAVA_OPTS=-Xms512m -Xmx1024m" #设置使用jvm内存大小
    ports:
      - "9200:9200"
    volumes:
      - "./es/certs:/usr/share/elasticsearch/config/certs"
      - "./es/data:/usr/share/elasticsearch/data"
    networks:
      - my-net

三、minIO启动失败

minio报错信息:

02:08:37.33 INFO  ==> ** Starting MinIO setup **
minio 02:08:37.37 INFO  ==> Starting MinIO in background...
minio 02:08:47.46 INFO  ==> Adding local Minio host to 'mc' configuration...
minio 02:08:52.59 INFO  ==> Adding local Minio host to 'mc' configuration...
minio 02:08:57.73 INFO  ==> Adding local Minio host to 'mc' configuration...
minio 02:09:02.80 INFO  ==> Adding local Minio host to 'mc' configuration...
minio 02:09:07.87 INFO  ==> Adding local Minio host to 'mc' configuration...
minio 02:09:12.95 INFO  ==> Adding local Minio host to 'mc' configuration...
minio 02:09:18.02 INFO  ==> Adding local Minio host to 'mc' configuration...
minio 02:09:23.09 INFO  ==> Adding local Minio host to 'mc' configuration...
minio 02:09:28.15 INFO  ==> Adding local Minio host to 'mc' configuration...
minio 02:09:33.22 INFO  ==> Adding local Minio host to 'mc' configuration...
minio 02:09:38.30 INFO  ==> Adding local Minio host to 'mc' configuration...
minio 02:09:43.36 INFO  ==> Adding local Minio host to 'mc' configuration...
Failed to add temporary MinIO server
minio 02:09:48.45 INFO  ==> MinIO is already stopped...

啥也看不出来对不对😂,这个问题我也在网上找了好久。看到了这篇博客

https://bootschool.net/article/62fa0463f301192a03817e2d/minio-docker-log-adding-local-minio-host-to-mc-configuration

解决办法

minio的账号长度必须大于等于5,密码长度必须大于等于8位)

minio:
    image: "bitnami/minio:latest"
    container_name: minio
    ports:
      - "9000:9000"
      - "9001:9001"
    environment:
      - MINIO_ROOT_USER=admin
      - MINIO_ROOT_PASSWORD=kaiyuan123
    volumes:
      - "./minio/data:/bitnami/minio/data"
    networks:
      - my-net

完整docker-compose文件

version: "3.8"

networks:
  my-net:
    name: gkynet

services:
  minio:
    image: "bitnami/minio:latest"
    container_name: minio
    ports:
      - "9000:9000"
      - "9001:9001"
    environment:
      - MINIO_ROOT_USER=admin
      - MINIO_ROOT_PASSWORD=kaiyuan123
    volumes:
      - "./minio/data:/bitnami/minio/data"
    networks:
      - my-net
  elasticsearch:
    image: "elasticsearch:7.17.5"
    container_name: es
    environment:
      - "TZ=Asia/Shanghai"
      - "cluster.name=elasticsearch" #设置集群名称为elasticsearch
      - "discovery.type=single-node" #以单一节点模式启动
      - "ES_JAVA_OPTS=-Xms512m -Xmx1024m" #设置使用jvm内存大小
    ports:
      - "9200:9200"
    volumes:
      - "./es/certs:/usr/share/elasticsearch/config/certs"
      - "./es/data:/usr/share/elasticsearch/data"
    networks:
      - my-net
  nginx:
    image: "nginx:latest"
    container_name: nginx
    environment:
      - "TZ=Asia/Shanghai"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "./nginx/html:/usr/share/nginx/html"
    networks:
      - my-net

总结

折腾了快一天终于搞完了。说明一下,这个是检验我们的docker compose掌握程度,因此里面的镜像没有提前拉取,挂载数据卷的目录也没有提前创建。虽然docker compose up执行后会自动帮你完成这些事,但正规的做法是把docker compose用到的东西提前准备好,这样能减少很多麻烦。
如果对你有帮助,可以给个赞😉


http://www.kler.cn/a/149136.html

相关文章:

  • Java面向对象编程进阶之包装类
  • uniapp使用scroll-view下拉刷新与上滑加载
  • 卓胜微嵌入式面试题及参考答案(2万字长文)
  • 探索Pillow库:Python图像处理的瑞士军刀
  • request爬虫库的小坑
  • 常用的Anaconda Prompt命令行指令
  • el-tabel实现拖拽排序
  • 绩效考核的基础及基本内容
  • NOI / 1.8编程基础之多维数组 提问24:蛇形填充数组 c语言
  • 进程和线程的关系
  • 力扣106. 从中序与后序遍历序列构造二叉树
  • linux(2)之buildroot使用手册
  • asp.net mvc游戏门户网站
  • 基于U2-Net如何训练一个一键抠图模型
  • 什么是量子优势?
  • 系列十六、Spring IOC容器的扩展点
  • vue3-10
  • 【C++】构造函数和析构函数第四部分(深拷贝和浅拷贝)--- 2023.11.25
  • Spring Boot 3 + Spring Security 6 最新版本修改 Json 登录后 RememberMe 功能问题失效的解决方案
  • NextJS开发:封装shadcn/ui中的AlertDialog确认对话框
  • windows系统mobaxterm远程执行linux上ssh命令
  • 中伟视界:AI智能分析盒子的人数统计AI算法通过什么算法模型可以解决重复统计的问题?
  • 【AI考证笔记】NO.1人工智能的基础概念
  • Mysql更新Blob存储的Josn数据
  • c++调用openssl对文件加解密
  • ubuntu配置免密登录vscode