WARNING: The "web" service is using the custom container name "fix10-cs-q4-web". Docker requires each container to have a unique name. Remove the custom name to scale the service — you asked for two containers of web with --scale web=2, and the service sets container_name:. Remove that line and the scale works.

Delete container_name: from the service and run the same command. Compose then names the containers itself, fix10-cs-q4-web-1 and fix10-cs-q4-web-2.

The error

PS> docker compose -p fix10-cs-q4 up -d --scale web=2
WARNING: The "web" service is using the custom container name "fix10-cs-q4-web". Docker requires each container to have a unique name. Remove the custom name to scale the service

It starts with WARNING, but the command exited with code 1, and docker compose -p fix10-cs-q4 ps -a afterwards listed no container at all: not even one copy was started. The file:

services:
  web:
    image: alpine
    command: ["sleep", "20"]
    container_name: fix10-cs-q4-web

Why it happens

container_name gives the service's container one fixed name. A container name has to be unique on the engine, as the message says, so a second container of the same service cannot take the same name. Compose refused the whole up rather than start one container and fail on the second.

Without container_name, Compose built each name from the project, the service and a number, fix10-cs-q4-web-1 and fix10-cs-q4-web-2, which is what made two copies possible. The message itself names the service and the fixed name it found, so in a file with many services you know which container_name line to delete.

The fix

services:
  web:
    image: alpine
    command: ["sleep", "20"]
PS> docker compose -p fix10-cs-q4 up -d --scale web=2
...
 Container fix10-cs-q4-web-1 Started
 Container fix10-cs-q4-web-2 Starting
 Container fix10-cs-q4-web-2 Started
PS> docker compose -p fix10-cs-q4 ps --format {{.Name}}
fix10-cs-q4-web-1
fix10-cs-q4-web-2

Two containers ran, numbered 1 and 2. If something outside Compose depends on the fixed name, the choice is between that name and more than one copy: the file with container_name could not be scaled to two.

This test used up -d, so both containers ran sleep 20 in the background while ps listed them, and down -v then stopped and removed both along with the network.

How it was reproduced

One alpine service running sleep 20 with container_name: fix10-cs-q4-web, started with docker compose up -d --scale web=2 from Windows PowerShell 5.1, then the same file without container_name. Docker Compose v5.7.0, Docker Engine 29.9.3, Docker Desktop 4.99.0 on Windows (version 10.0.26300). The project and container names with fix10-cs-q4 are this test's own; the project was removed with docker compose down -v.

Frequently asked

Why can't I scale a service with container_name in docker compose?
The message says it: Docker requires each container to have a unique name. Remove the custom name to scale the service. Compose refused docker compose up --scale web=2 and started nothing in this test.
Is the custom container name warning only a warning?
No. The line starts with WARNING, but the command exited with code 1 and no container was created in this test.
How do I scale a docker compose service to two containers?
Remove container_name from the service and run docker compose up -d --scale web=2. In this test Compose then started web-1 and web-2 with names it chose itself.

More decoded errors in the Fixes category. For a fixed name that clashes with an existing container, see Docker: the container name is already in use.