How to update only one service

in docker stack

Published:
Published:

Table of contents

If you have two applications and one database in a stack then the docker-compose.yml file looks like this

version: "3.3"

services:
  app1:
    image: custom-image-app1
    ports:
      - "8000:8000"
  app2:
    image: custom-image-app2
    ports:
      - "8080:8080"
  db:
    image: postgres:14
    environment:
      POSTGRES_DB: mydatabase
      POSTGRES_USER: myuser
      POSTGRES_PASSWORD: mypassword
    ports:
      - "5432:5432"

Let's say you have an update only in one application. How do you update the stack? If you run

docker stack down my_stack
docker build . -t my-app
docker stack up -c docker-compose.yml my_stack

then you are doing everything wrong!

After building a new image (or pulling it from the registry) you can update only the specific service with this command

docker service update --force --update-parallelism 1 --update-delay 5s my_stack_app1

About logs

Check logs like this

docker service logs -f my_stack_app1

Set log rotation by editing /etc/docker/daemon.json

{
  "log-driver": "local",
  "log-opts": {
    "max-size": "10m"
  }
}

Reference: https://docs.docker.com/config/containers/logging/local/

Rate this page