用docker compose部署服务
docker compose可以方便我们快捷高效地管理容器的启动、停止、重启等操作,它类似linux下的shell脚本,基于yaml语法,在该文件里我们可以描述应用的架构,比如用什么镜像、数据卷、网络模式、监听端口等信息。我们可以在一个compose文件中定义一个多容器的应用,然后通过该compose来启动这个应用。
下载安装docker-compose
# curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-Linux-x86_64 > /usr/local/bin/docker-compose
# chmod 755 /usr/local/bin/docker-compose
[root@apenglinux-002 ~]# docker-compose version
docker-compose version 1.21.0, build 5920eb0
docker-py version: 3.2.1
CPython version: 3.6.5
OpenSSL version: OpenSSL 1.0.1t 3 May 2016
编辑docker-compose.yml
version: "2"
services:
app1:
image: centos:nginx
ports:
- "8080:80"
networks:
- "net1"
volumes:
- /data/:/data
app2:
image: centos:net-tools
networks:
- "net2"
volumes:
- /data/:/data1
entrypoint: tail -f /etc/passwd
networks:
net1:
driver: bridge
net2:
driver: bridge
启动所有的容器
查看运行的容器
docker-compose的命令 docker-compose --help
[root@apenglinux-002 ~]# docker-compose start
[root@apenglinux-002 ~]# docker-compose down
Stopping root_app2_1 ... done
Stopping root_app1_1 ... done
Removing root_app2_1 ... done
Removing root_app1_1 ... done
Removing network root_net1
Removing network root_net2
[root@apenglinux-002 ~]# docker-compose ps
Name Command State Ports
------------------------------
转载于:https://blog.51cto.com/13480443/2097560