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