Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 260
Samizdis Avatar asked Nov 02 '17 17:11

Samizdis


People also ask

Does docker-compose-f--force-recreate rebuild the container?

I would greatly appreciate your insight. Upon executing docker-compose -f custom-filename.yml up --force-recreate app or docker-compose -f custom-filename.yml up --force-recreate container is not rebuilt.

How to recreate a service in Docker?

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.

What does $docker compose up do?

$ docker compose up [SERVICE...] Builds, (re)creates, starts, and attaches to containers for a service. Unless they are already running, this command also starts any linked services. The docker compose up command aggregates the output of each container (liked docker compose logs --follow does). When the command exits, all containers are stopped.

What is the difference between ‘–force-recreate’ and ‘—no-re create’ in Docker containers?

The ‘–force-recreate’ flag is used to recreate the containers even if there is no configuration changes are made to the ‘docker-compose.yml’ file whereas if we have made some changes to the file but don’t want to recreate the containers if it is already running then we use the ‘—no-recreate’ flag.


2 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.

like image 113
Fisher Yu Avatar answered Oct 14 '22 21:10

Fisher Yu


to rebuild only 'mysql' service, run this command

docker-compose up --force-recreate --no-deps mysql 
like image 38
Sanaullah Ahmad Avatar answered Oct 14 '22 20:10

Sanaullah Ahmad