docker

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > 云和虚拟化 > docker > Docker compose启动服务

Docker compose启动服务遇到的问题小结

作者:农专猿

这篇文章主要介绍了Docker compose启动服务遇到的问题小结,这个是检验我们的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

原因:

解决办法

使配置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://www.jb51.net/server/3064586fv.htm

解决办法

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用到的东西提前准备好,这样能减少很多麻烦。
如果对你有帮助,可以给个赞😉

到此这篇关于Docker compose启动服务遇到的问题的文章就介绍到这了,更多相关Docker compose启动服务内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文