Docker(八)用docker compose部署服務
阿新 • • 發佈:2018-04-12
docker用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 ------------------------------
Docker(八)用docker compose部署服務