My docker-compose.yml
:
services:
service1:
image: image1
service2:
image: image2
service3:
image: image3
deploy:
replicas: 0
The replicas: 0
ensures the service only starts on demand: I don’t want to it to start automatically.
Assuming that compose project isn’t running; I want to start service3
only:
docker compose up -d --scale service3=1
That starts service3
, but also service1
and service2
.
How can I start service3
only?
Note:
- docker swarm is not an option in this case
- docker profiles are not an option in this case (it has some issues)
2
Answers
You have to use the docker compose up command:
or, docker compose start command if the container already exist:
In case you don’t want to re-create services, as workaround, you can either set the replicas also on the other services by adding to service1 and service2:
or use the –scale option
If you want to only start one service when using
docker compose up
, you have to specify the said service as an argument of your command, as shown in the help of the command:So, in your case you have to do:
If we split it down:
Which gives: