Feedback

Chat Icon

Painless Docker - 2nd Edition

A Comprehensive Guide to Mastering Docker and its Ecosystem

Deploying and Managing Services at Scale with Docker Swarm
91%

Docker Swarm Rolling Updates

In the previous steps, we updated the stack by executing the docker stack deploy command. However, how can we achieve the same operation while limiting the downtime of the services? For instance, if we want to update the WordPress image to a new version, we don't want to stop all the containers and start new ones with the new image. This is where rolling updates come into play.

A rolling update is a deployment strategy that updates the services one by one.

Let's see how to accomplish this. First, we need to modify the docker-compose.yml file to use the rolling update strategy:

cat < docker-compose.yml
version: '3.9'

services:
   db:
     image: mysql:9.6.0
     volumes:
       - db_data:/var/lib/mysql
     environment:
       MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD_FILE: /run/secrets/db_password
     secrets:
       - db_root_password
       - db_password
     networks:
       - wordpress-network
     deploy:
       placement:
         constraints:
           - node.role==manager
       resources:
         limits:
           cpus: '1'
           memory: 800M
         reservations:
           cpus: '0.5'
           memory: 500M
       update_config:
         parallelism: 1
         delay: 10s
         order: start-first

   wordpress:
     depends_on:
       - db
     image: wordpress:6.9.1-apache
     ports:
       - "8000:80"
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER

Painless Docker - 2nd Edition

A Comprehensive Guide to Mastering Docker and its Ecosystem

Enroll now to unlock all content and receive all future updates for free.

Unlock now  $31.99$25.59

Hurry! This limited time offer ends in:

To redeem this offer, copy the coupon code below and apply it at checkout:

Learn More