Samizdis
Samizdis

Reputation: 1661

Docker-compose --force-recreate specific service

I have a container in my stack that needs to be recreated each time I docker-compose up. I can docker-compose up --force-recreate but this recreates all my containers. Is there syntax (maybe for the docker-compose.yml file) for specifying this kind of flag per-service?

Upvotes: 39

Views: 31463

Answers (3)

user14967413
user14967413

Reputation: 1416

You can simply remove the old container before running services, which means that new container will be created.

docker container rm <container-name> && docker-compose up

You can find <container-name> by running docker ps -a. As far as you don't change directory name or project name, container name should stay the same.

Note that after removing the container its named volumes will still be preserved.

Upvotes: 0

Sanaullah Ahmad
Sanaullah Ahmad

Reputation: 508

to rebuild only 'mysql' service, run this command

docker-compose up --force-recreate --no-deps mysql

Upvotes: 1

Fisher Yu
Fisher Yu

Reputation: 569

If your service depends on (or links to) other services, you can try:

docker-compose up --force-recreate --no-deps service-name

This will only recreate the specified service, linked or depended services will keep untouched.

Upvotes: 56

Related Questions