Update Docker Image on Docker Swarm Cluster

Update Docker Image pada Docker Swarm Cluster

  • Pastikan sudah menginstall docker swarm cluster
  • image: sysopsid/web-test:v1 menggunakan php versi 8.1
  • image: sysopsid/web-test:v2 menggunakan php versi 8.2

  • Buat service dengan nama web_sys-ops-id, jumlah replikasi ada 2 dengan update-delay 1menit 10 detik (jarak update dari task1 ke task lainnya/partial update) update-parallelism 1 (jumlah task update yang dapat berjalan bersamaan) dan menggunakan image: sysopsid/web-test:v1 dengan publish port 8080
docker service create --replicas 2 --publish 8080:80 --name web_sys-ops-id --update-delay 1m10s --update-parallelism 1 --rollback-delay 30s --rollback-parallelism 1 sysopsid/web-test:v1
---<output>---
qa0nlc0q3pbwwstz6uar0jp7g
overall progress: 2 out of 2 tasks
1/2: running   [==================================================>]
2/2: running   [==================================================>]
verify: Service converged
  • Cek status docker service
docker service ps web_sys-ops-id
---<output>---
ID             NAME               IMAGE                  NODE      DESIRED STATE   CURRENT STATE            ERROR     PORTS
susqbdtalln5   web_sys-ops-id.1   sysopsid/web-test:v1   node02    Running         Running 23 seconds ago
ma91m49kirhp   web_sys-ops-id.2   sysopsid/web-test:v1   node01    Running         Running 22 seconds ago
  • Inspect docker service
docker service inspect --pretty web_sys-ops-id
---<output>---
ID:             qa0nlc0q3pbwwstz6uar0jp7g
Name:           web_sys-ops-id
Service Mode:   Replicated
 Replicas:      2
Placement:
UpdateConfig:
 Parallelism:   1
 Delay:         1m10s
 On failure:    pause
 Monitoring Period: 5s
 Max failure ratio: 0
 Update order:      stop-first
RollbackConfig:
 Parallelism:   1
 Delay:         30s
 On failure:    pause
 Monitoring Period: 5s
 Max failure ratio: 0
 Rollback order:    stop-first
ContainerSpec:
 Image:         sysopsid/web-test:v1@sha256:2b2d9d69c1ba7769f08068d871ed7cc77751c2590e1e0d0a1c1ad3d079feb205
 Init:          false
Resources:
Endpoint Mode:  vip
Ports:
 PublishedPort = 8080
  Protocol = tcp
  TargetPort = 80
  PublishMode = ingress
  • Verifikasi, akses docker serivce lewat browser (tampilan sebelum di update)

  • Update docker image menggunakan image: sysopsid/web-test:v2
docker service update --image sysopsid/web-test:v2 web_sys-ops-id
---<output>---
web_sys-ops-id
overall progress: 2 out of 2 tasks
1/2: running   [==================================================>]
2/2: running   [==================================================>]
verify: Service converged
  • Inspect docker service, pastikan update status dan message dalam keadaan completed
  • Jika update status-nya paused dengan message failure, artinya update mengalami masalah/gagal, lakukan restart update dengan cara: docker service update web_sys-ops-id
docker service inspect --pretty web_sys-ops-id
---<output>---
ID:             qa0nlc0q3pbwwstz6uar0jp7g
Name:           web_sys-ops-id
Service Mode:   Replicated
 Replicas:      2
UpdateStatus:
 State:         completed
 Started:       5 minutes ago
 Completed:     About a minute ago
 Message:       update completed
Placement:
UpdateConfig:
 Parallelism:   1
 Delay:         1m10s
 On failure:    pause
 Monitoring Period: 5s
 Max failure ratio: 0
 Update order:      stop-first
RollbackConfig:
 Parallelism:   1
 Delay:         30s
 On failure:    pause
 Monitoring Period: 5s
 Max failure ratio: 0
 Rollback order:    stop-first
ContainerSpec:
 Image:         sysopsid/web-test:v2@sha256:9351d2fd748db412faa3bb1d28598bdb5573f23c0d9745da2e502d0e1126a009
 Init:          false
Resources:
Endpoint Mode:  vip
Ports:
 PublishedPort = 8080
  Protocol = tcp
  TargetPort = 80
  PublishMode = ingress
  • Cek status docker service, container yang running sudah menggunakan image terbaru: sysopsid/web-test:v2
docker service ps web_sys-ops-id
---<output>---
ID             NAME                   IMAGE                  NODE      DESIRED STATE   CURRENT STATE            ERROR     PORTS
rgv9jn84ge7d   web_sys-ops-id.1       sysopsid/web-test:v2   node02    Running         Running 2 minutes ago
susqbdtalln5    \_ web_sys-ops-id.1   sysopsid/web-test:v1   node02    Shutdown        Shutdown 2 minutes ago
89q6c3rzj92u   web_sys-ops-id.2       sysopsid/web-test:v2   node01    Running         Running 3 minutes ago
ma91m49kirhp    \_ web_sys-ops-id.2   sysopsid/web-test:v1   node01    Shutdown        Shutdown 3 minutes ago
  • Verifikasi, akses docker serivce lewat browser (tampilan sesudah di update)

  • Rollback docker service
docker service rollback web_sys-ops-id

herdiana3389

A system administrator with skills in system administration, virtualization, linux, windows, networking, cloud computing, container, etc.