场景:平时我们开发环境中常需要安装这些软件,nginx,pgsql或者mysql,redis,rabbit或者kafka或者nsq;可能要搞好多环境开发,测试,某版本测试,预上线等等。卓个案转费时费力
提供个docker快速一键部署方式
docker-compose
写一个 dockercompose.yml 文件
就用两个命令:
启动
docker-compose -f dockercompose.yml up -d
停止
docker-compose -f dockercompose.yml down
上文件内容
把里面的用户命 和 密码部分改一下就能用
version: '3'
services:
nginx:
image: nginx:1.23.3
container_name: nginx
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- /www/logs/nginx/:/var/log/nginx/
- /www/server/nginx/conf.d:/etc/nginx/conf.d
- /www/server/nginx/nginx.conf:/etc/nginx/nginx.conf
pgsql:
image: postgres:15.1
container_name: pgsql
restart: always
ports:
- "5432:5432"
volumes:
- /www/server/pgsql/db:/var/lib/postgresql/data
environment:
- POSTGRES_USER=数据库用户名
- POSTGRES_PASSWORD=数据库明密码
redis:
image: redis:7.0.7
container_name: redis
restart: always
ports:
- "6379:6379"
volumes:
- /www/server/redis/:/data/redis/:rw
- /www/server/redis/db:/data/redis/db:rw
command: redis-server /data/redis/redis.conf
rabbit:
image: rabbitmq:3.11.5-management
container_name: rabbit
restart: always
ports:
- "15672:15672"
- "5672:5672"
volumes:
- /www/server/rabbitmq/data/:/var/lib/rabbitmq:rw
- /www/logs/rabbitmq/:/var/log/rabbitmq:rw
environment:
- RABBITMQ_DEFAULT_USER=rabbit用户名
- RABBITMQ_DEFAULT_PASS=rabbit密码
# chmod -R 777 /www/logs/rabbitmq
Docker Compose命令不熟的可以自行查下,没几条命了
看下配置文件中的目录可能需要建一下
执行启动后(docker-compose -f dockercompose.yml up -d),
docker ps 一下可以看到全部起来了,完事
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
adf9c71b65dd rabbitmq:3.11.5-management "docker-entrypoint.s…" 2 weeks ago Up 2 weeks 4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp rabbit
ce79979fa7a2 nginx:1.23.3 "/docker-entrypoint.…" 2 weeks ago Up 2 weeks 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp nginx
f0ad01978a53 redis:7.0.7 "docker-entrypoint.s…" 2 weeks ago Up 2 weeks 0.0.0.0:6379->6379/tcp redis
383ef620dada postgres:15.1 "docker-entrypoint.s…" 2 weeks ago Up 2 weeks 0.0.0.0:5432->5432/tcp pgsql