brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker compose up --scale runs several copies of a service

Docker
~/tips/tip-compose-up-scale

docker compose up -d --scale worker=3

Starts a chosen number of copies of one compose service.

Sometimes one worker is too slow and I want three, without touching the compose file. The --scale flag on up does that.

Give it the service name and a number:

docker compose up -d --scale worker=3

The flag overrides the scale setting in the compose file, if there is one, and scaling down works the same way with a smaller number. A service can also carry a default in the file:

services:
  worker:
    image: example/worker:latest
    scale: 3

Compose numbers the copies inside the project, so you get worker-1, worker-2 and worker-3 with the project name in front. docker compose logs -f worker prefixes each line with the copy it came from, and docker compose port --index 2 worker 80 asks for the port of the second one.

Caveats: a service with container_name set cannot scale beyond one container, because the names would clash. A fixed host port such as 8080:80 can only be taken by one container, so extra copies need a published port range, or no published port and a proxy in front.

Further reading: docker compose up, Compose services: scale

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link