这是学长留的一个任务,用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 挂载的目录路径
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报错信息:
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
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用到的东西提前准备好,这样能减少很多麻烦。
如果对你有帮助,可以给个赞