建 docker-compose 文件
volumes中挂载的目录当宿主机不存在时,会自动创建
vi docker-compose.yml
version: "2" # 使用Version 2
services: # 包含需要操作的容器
web1: # 容器的名称
image: nginx # 指定基于哪个镜像
ports: # 指定映射的端口
- "8080:80"
networks: # 指定使用哪个网络模式
- "net1"
volumes: # 指定挂载的的目录
- /data/www:/usr/share/nginx/html
web2:
image: nginx
ports:
- "8081:80"
networks:
- "net2"
volumes:
- /data/www1:/usr/share/nginx/html
networks:
net1:
driver: bridge
net2:
driver: bridge
docker-compose文件内容区域
查看容器状态
[root@mysql1 opt]# docker-compose ps
Name Command State Ports
opt_web1_1 nginx -g daemon off; Up 0.0.0.0:8080->80/tcp
opt_web2_1 nginx -g daemon off; Up 0.0.0.0:8081->80/tcp
停止已有的容器:
[root@server ~]# docker-compose stop
Stopping root_app1_1 ... done
Stopping root_app2_1 ... done
[root@server ~]#
启动已有的容器:
[root@server ~]# docker-compose start
Starting app2 ... done
Starting app1 ... done
[root@server ~]#
查看容器的状态:
[root@server ~]# docker-compose ps
Name Command State Ports
root_app1_1 /bin/sh -c /usr/local/ngin ... Exit 137
root_app2_1 tail -f /etc/passwd Exit 137
[root@server ~]#
删除容器:
[root@server ~]# docker-compose rm -f
Going to remove root_app1_1, root_app2_1
Removing root_app1_1 ... done
Removing root_app2_1 ... done
[root@server ~]#
停止并删除运行中的容器:
[root@server ~]# docker-compose down
Stopping root_app1_1 ... done
Stopping root_app2_1 ... done
Removing root_app1_1 ... done
Removing root_app2_1 ... done
Removing network root_net2
Removing network root_net1
[root@server ~]# docker-compose ps
Name Command State Ports
[root@server ~]#
docker-compose编排最佳实战(多服务)
原文:http://blog.51cto.com/10158955/2152512