I have a a script which builds docker image, loads it to docker, updates docker-compose.yml
then it calls docker compose down
and docker compose up
. After the Docker compose up
services are recreated and service which i’m interesting for is running with correct (new) version.
I don’t want to stop all services, which are stopped by docker compose down
, i want to stop the only target one. I found that both docker compose up
and docker compose down
supports specifying service name
down:
https://forums.docker.com/t/docker-compose-down-specific-service/125914/8
https://docs.docker.com/reference/cli/docker/compose/down/
up:
https://docs.docker.com/reference/cli/docker/compose/up/
But when i call docker compose down myservicename
in Docker version 25.0.3
i receive error: unknown command "myservicename" for "docker compose down"
How to stop (and remove) only one container ?
May be there is another way to "update image" for only one container?
2
Answers
I found the following solution just
docker compose up -d servicename
, without anydocker compose down
anddocker compose rm
.In response i receive:
So, according to the output i can conclude container was recreated.
Despite others say it will be better to "stop and remove" old container, before recreating, i decided to post this answer, may be it will be useful for some one. In general i agree, - "stop and remove" the container ensures a clean restart.
You should use a combination of docker compose stop and docker compose rm commands, which do allow specifying a service name.
Stop the specific service: First, you need to stop the service if it’s running
Remove the stopped service container: After stopping the service, you can remove its container.
Update and restart the specific service: Now that the specific service is stopped and removed, you can proceed to update its image and restart it.