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?
3 Answers
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.
2 Comments
Volvox
Note -
service-name is name defined in docker-compose.yml (so php, not project_php_1).Alexandr S.
docker compose up -d --force-recreate --no-deps service-name Worked for me thanks.to rebuild only 'mysql' service, run this command
docker-compose up --force-recreate --no-deps mysql
2 Comments
YSC
What does it add to the earlier, most upvoted answer?
Sanaullah Ahmad
Its just add some more explanation with an example service i-e "mysql".
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.
docker-compose updoesn't work with swarm mode.