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.
Description. 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 (like docker compose logs --follow does).
'docker-compose up' is a Docker command to start and run an entire app on a standalone host that contains multiple services, for example, Web, DB, etc. It can also create volumes and networks at the same time and attach to the containers that are defined in a file called 'docker-compose.
Docker Compose is an orchestration tool for Docker that allows you to define a set of containers and their interdependencies in the form of a YAML file. You can then use Docker Compose to bring up part or the whole of your application stack, as well as track application output, etc.
The run command acts like docker run -ti in that it opens an interactive terminal to the container and returns an exit status matching the exit status of the process in the container. The docker compose start command is useful only to restart containers that were previously created, but were stopped.
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.
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