Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yangl/51894684a13bcacfdad45c6957d1aa88 to your computer and use it in GitHub Desktop.
Save yangl/51894684a13bcacfdad45c6957d1aa88 to your computer and use it in GitHub Desktop.
新版Docker的Swarm模式 创建|部署|扩展|删除,详见:http://www.dockerinfo.net/3837.html

1.快速安装docker:

参见daocloud http://get.daocloud.io/#install-docker

curl -sSL https://get.daocloud.io/docker | sh

2.启动docker:

systemctl enable docker

systemctl status docker

systemctl start docker

systemctl restart docker

3.创建swarm机群

  • manager上执行:
docker swarm init --advertise-addr 10.45.41.211
  • 查看状态:
docker info
docker node ls
  • 如果忘记了token,可执行如下查看:
docker swarm join-token worker
  • 然后添加woker
docker swarm join \
    --token SWMTKN-1-2ch5ug4apnq2gge6j8dq9o9mxu392afcj2gcsvnc2jc913qmoz-35tv88g9bhptxejxc0pg5synk \
    10.45.41.211:2377
  • 再次查看状态:
docker node ls  
ID                           HOSTNAME      STATUS  AVAILABILITY  MANAGER STATUS
33539ggadcqrqmzejkspqrc41 *  ALYBJ74-42    Ready   Active        Leader
3ki38426ed3ew2y5n0l4tlhym    ALYBJ150-90   Ready   Active        
809pel5gvrrhvu23o2cd4ruta    ALYBJ150-134  Ready   Active 
  • 部署服务
docker service create --replicas 2 --name helloworld alpine ping docker.com

docker service ls

ID            NAME        REPLICAS  IMAGE   COMMAND
8yoaan1mipwp  helloworld  1/2       alpine  ping docker.com

ID:             8yoaan1mipwpg26ffvkjgdpb5
Name:           helloworld
Mode:           Replicated
 Replicas:      2
Placement:
UpdateConfig:
 Parallelism:   1
 On failure:    pause
ContainerSpec:
 Image:         alpine
 Args:          ping docker.com
Resources:


docker service scale helloworld=3

docker service ps helloworld

ID                         NAME          IMAGE   NODE          DESIRED STATE  CURRENT STATE               ERROR
9rfm7n3fomdqswcj38ffafn1l  helloworld.1  alpine  ALYBJ74-42    Running        Running 2 minutes ago       
czurd89pdda0ies2djfj985gn  helloworld.2  alpine  ALYBJ150-134  Running        Running about a minute ago  
0imp0ycychvob3xbdualni7ho  helloworld.3  alpine  ALYBJ150-90   Running        Running 50 seconds ago


docker service rm helloworld
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment