docker-compose编写
docker-compose参数说明
Docker Compose 提供了多个参数,用于配置和管理 Docker 容器和服务。以下是 Docker Compose 常用的参数:
version
:指定 Docker Compose 文件的版本。services
:定义各个服务的配置信息。image
:指定服务所使用的镜像。build
:指定 Dockerfile 的路径,用于构建镜像。ports
:指定容器和主机之间的端口映射关系。volumes
:指定容器和主机之间的卷挂载关系。environment
:设置容器的环境变量。networks
:指定服务所连接的网络。depends_on
:指定服务之间的依赖关系。restart
:指定容器的重启策略。command
:覆盖容器启动时的默认命令。links
:连接容器与容器之间的网络连接。volumes_from
:从其他容器或服务中挂载卷。expose
:暴露容器内部的端口。extends
:继承其他服务的配置。external_links
:连接外部的容器或服务。
启动docker-compose
docker-compose up
# 后台运行容器
docker-compose up -d
修改默认数据卷存放位置
默认数据卷配置目录/etc/docker
,修改其中的daemon.json
或者是setting.json
vim /etc/docker/daemon.json
# 或者
vim /etc/docker/setting.json
查看所有网络
docker network ls
创建
如果在配置文件中指定了volumes
,在最后的末尾需要添加,如:
volumes:
minio_data:
如果指定了网络networks
,如:
networks:
config_network:
参考配置文件
version: '3'
services:
minio:
image: minio/minio
volumes:
- minio_data:/data
ports:
- "9000:9000"
environment:
- MINIO_ROOT_USER=admin
- MINIO_ROOT_PASSWORD=123456
mysql_3304:
image: mysql:8.0.33
volumes:
- mysql_data_3304:/var/lib/mysql
ports:
- "3304:3304"
environment:
- MYSQL_ROOT_PASSWORD=123456
- MYSQL_DATABASE=gitea
- MYSQL_USER=root
- MYSQL_PASSWORD=123456
mysql_3305:
image: mysql:8.0.33
volumes:
- mysql_data_3305:/var/lib/mysql
ports:
- "3305:3305"
environment:
- MYSQL_ROOT_PASSWORD=123456
- MYSQL_DATABASE=mysql
- MYSQL_USER=root
- MYSQL_PASSWORD=123456
mysql_3306:
image: mysql:8.0.33
volumes:
- mysql_data_3306:/var/lib/mysql
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=123456
- MYSQL_DATABASE=mysql
- MYSQL_USER=root
- MYSQL_PASSWORD=123456
# harbor:
# image: goharbor/harbor:v2.3.0
# networks:
# - config_network
# ports:
# - "80:80"
# - "443:443"
# volumes:
# - harbor_data:/data
# - harbor_registry:/harbor_registry
# - harbor_chartmuseum:/harbor_chartmuseum
# - harbor_logs:/var/log
# environment:
# - HARBOR_ADMIN_PASSWORD=admin
# - HARBOR_DB_PASSWORD=123456
redis:
image: redis:latest
volumes:
- redis_data:/data
- ./redis_conf:/usr/local/etc/redis/redis.conf
command: redis-server /usr/local/etc/redis/redis.conf
ports:
- "6379:6379"
rabbitmq:
image: rabbitmq:3-management
ports:
- "5672:5672"
- "15672:15672"
volumes:
- rabbitmq_data:/var/lib/rabbitmq
- ./rabbitmq_conf:/etc/rabbitmq/rabbitmq.conf
nacos:
image: nacos/nacos-server:v2.1.0-slim
networks:
- config_network
volumes:
- nacos_data:/home/nacos/custom.env
environment:
- MODE=standalone
- SPRING_DATASOURCE_PLATFORM=mysql
- MYSQL_SERVICE_HOST=localhost
- MYSQL_SERVICE_PORT=3304
- MYSQL_SERVICE_DB_NAME=nacos
- MYSQL_SERVICE_USER=nacos
- MYSQL_SERVICE_PASSWORD=nacos
ports:
- "8848:8848"
- "9848:9848"
- "9849:9849"
gitea:
image: gitea/gitea:latest
networks:
- config_network
ports:
- "3000:3000"
environment:
- DB_TYPE=mysql
- DB_HOST=localhost
- DB_PORT=3304
- DB_USER=root
- DB_PASSWD=password
volumes:
- gitea_data:/data
- ./gitea_config:/etc/gitea
jenkins:
image: jenkins/jenkins
ports:
- "8080:8080"
- "50000:50000"
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
ports:
- "9200:9200"
- "9300:9300"
networks:
config_network:
volumes:
minio_data:
mysql_data_3304:
mysql_data_3305:
mysql_data_3306:
harbor_data:
harbor_registry:
harbor_chartmuseum:
harbor_logs:
rabbitmq_data:
rabbitmq_conf:
redis_data:
nacos_data:
gitea_data:
gitea_config: