對 Docker swarm 中 service 進行 rolling update

當在 Docker swarm 群集中有更新版本的 docker image 要部署時,我們可以透過以下步驟進行:

  1. 在 service 建立時,指定 update-delay 時間,讓 Docker 依照這個間隔依序下載新的 image 並部署(重啟 container):

如果要拉 private docker registry 的話,先 docker login 後傳遞 –with-registry-auth 參數在下面的指令

1
2
3
4
5
docker service create \
--replicas 3 \
--name redis \
--update-delay 10s \
redis:3.0.6
  1. 部署新版本時,使用 update 指令開始 rolling update:
1
docker service update --image redis:3.0.7 redis
  1. 透過 inspectps 指令觀察其更新情形:
1
docker service inspect --pretty redis
1
2
3
4
5
6
7
8
9
10
11
12
13
ID:             0u6a4s31ybk7yw2wyvtikmu50
Name: redis
Service Mode: Replicated
Replicas: 3
Placement:
Strategy: Spread
UpdateConfig:
Parallelism: 1
Delay: 10s
ContainerSpec:
Image: redis:3.0.7
Resources:
Endpoint Mode: vip
1
docker service ps redis
1
2
3
4
5
6
7
NAME                                   IMAGE        NODE       DESIRED STATE  CURRENT STATE            ERROR
redis.1.dos1zffgeofhagnve8w864fco redis:3.0.7 worker1 Running Running 37 seconds
\_ redis.1.88rdo6pa52ki8oqx6dogf04fh redis:3.0.6 worker2 Shutdown Shutdown 56 seconds ago
redis.2.9l3i4j85517skba5o7tn5m8g0 redis:3.0.7 worker2 Running Running About a minute
\_ redis.2.66k185wilg8ele7ntu8f6nj6i redis:3.0.6 worker1 Shutdown Shutdown 2 minutes ago
redis.3.egiuiqpzrdbxks3wxgn8qib1g redis:3.0.7 worker1 Running Running 48 seconds
\_ redis.3.ctzktfddb2tepkr45qcmqln04 redis:3.0.6 mmanager1 Shutdown Shutdown 2 minutes ago

References