Reputation: 1661
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
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
Reputation: 508
to rebuild only 'mysql' service, run this command
docker-compose up --force-recreate --no-deps mysql
Upvotes: 1
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