What is the difference between the `--build` and `--force-recreate` flags to `docker-compose up`?

Viewed 9814

Just as the title asks; what is the difference between the --build and --force-recreate flags to docker-compose up?

To me it seem that these would do the same thing, but maybe I am missing something.

2 Answers

As mentioned in a doc, or the help of docker-compose up,

--build: build images before starting containers.

--force-recreate: Recreate containers even if their configuration and image haven't changed.

--build is a straightforward and it will create the docker images before starting the containers. The --force-recreate flag will stop the currently running containers forcefully and spin up all the containers again even if you do not have changed anything into it's configuration. So, if there are any changes, those will be picked-up into the newly created containers while preserving the state of volumes. The counter to this is --no-recreate to keep the containers in their existing state and it will not consider the respective changes into the configuration.

Hope this helps.

--build: - rebuilds images(not containers - as --force-recreate does) according to the newest changes, normally it does not automatically update/builds them

--force-recreate: - recreates containers meaning that things like commands history is preserved, also some installed utilities, due to that, of course, the previous containers must be stopped and therefore is many times "incorrectly" misused as a shortcut for stopping and starting=restarting containers with a single command for instance when one makes runtime-affecting capable changes, eg as php values configurations by environmental variables and wants to see them immediately, fastly, etc

Related