image 使用的镜像
build 指定Dockerfile构建
command 启动执行命令
links 链接其他容器
ports 端口映射
expose 暴露端口
volumes 挂载路径
volumes_from 从容器挂载
environment 环境变量
举个栗子:
mx_mysql:
restart: always
image: mysql:5.6
volumes:
- /root/data/mysql:/var/lib/mysql
- ./conf/:/etc/mysql/conf.d
ports:
// 前面的3306表示宿主容器的端口,后面的3306表示容器内部的端口
- "3306:3306"
environment:
- MYSQL_DATABASE=online
- MYSQL_ROOT_PASSWORD=123456
mx_redis:
restart: always
image: redis:3.2
volumes:
- /root/data/redis:/data
ports:
- "6379:6379"
command: redis-server --appendonly yes
mx_nginx:
restart: always
image: nginx
ports:
- "80:80"
volumes:
- ./conf/mx_nginx.conf:/etc/nginx/conf.d/mx_nginx.conf
volumes_from:
- mx_online
links:
- mx_online:web
mx_online:
restart: always
build: .
expose:
- "8000:8000"
volumes:
- .:/online
links:
- mx_mysql:mysql
- mx_redis:redis
command: uwsgi -s :8000 -w online.wsgi -p 3
mx_celery:
restart: always
build: .
volumes_from:
- mx_online
links:
- mx_mysql:mysql
- mx_redis:redis
command: celery -A online worker -l info
启动的命令:docker-compose up -d 后台启动应用