Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 450
Vorticity Avatar asked Aug 30 '18 23:08

Vorticity


People also ask

What is the difference between docker compose build and up?

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

What does docker compose up mean?

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

What does docker compose build do?

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.

Can you tell the what are the purposes of up run and start commands of docker compose?

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.


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

like image 83
mohan08p Avatar answered Oct 01 '22 06:10

mohan08p