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?
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.
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.
$ 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.
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.
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.
to rebuild only 'mysql' service, run this command
docker-compose up --force-recreate --no-deps mysql
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With