Docker 再学习 (8) docker compose

Submitted by Lizhe on Tue, 02/26/2019 - 06:02

 

先初始化一个swarm

[root@machine1 ~]# docker swarm init --advertise-addr 172.16.166.135
Swarm initialized: current node (p4naje76eqgmvsf3wtcjx58ws) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-0w4jrw1p1pd8t43gwqzssuhzzqqe8cl6bfx72t7r4ks2ouq0uj-5c6w8mftv7m5rmsdtv81uqyum 172.16.166.135:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
 

 

安装

 

[root@machine1 yamls]# sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617    0   617    0     0    639      0 --:--:-- --:--:-- --:--:--   639
100 11.2M  100 11.2M    0     0  87845      0  0:02:13  0:02:13 --:--:--  125k
[root@machine1 yamls]# 
[root@machine1 yamls]# sudo chmod +x /usr/local/bin/docker-compose
[root@machine1 yamls]# docker-compose -version
docker-compose version 1.23.2, build 1110ad01
[root@machine1 yamls]#

 

通过compose 文件创建一个 nginx 集群

 

[root@machine1 yamls]# cat docker-compose.yaml 
version: "3"
services:
  nginxservice:
    image: nginxdemos/hello
    deploy:
      mode: replicated
      replicas: 6
    networks:
      - myoverlay
    ports:
      - "80:80"
      - "81:81"
networks:
  myoverlay:
    driver: overlay
    ipam:
      driver: default
      config:
      - subnet: 192.168.0.0/24
[root@machine1 yamls]# 
[root@machine1 yamls]# docker stack deploy --compose-file docker-compose.yaml stackdemo
Creating service stackdemo_nginxservice
[root@machine1 yamls]# 
[root@machine1 yamls]# docker network ls
NETWORK ID          NAME                  DRIVER              SCOPE
14d27b6d2ce5        bridge                bridge              local
a523f7a843bc        docker_gwbridge       bridge              local
f5b2c30e8ca9        host                  host                local
n2w5m0cx0u4g        ingress               overlay             swarm
449b37124c3a        none                  null                local
kx18h1t0rd58        stackdemo_myoverlay   overlay             swarm
39l54sing2xm        swarm_ov_network      overlay             swarm
[root@machine1 yamls]#  

20190226050408

20190226050737