What's the difference between docker-compose -up -d and docker-compose up -build?

Viewed 2781

I'm wondering what is the difference between those two commands?

When I'm doing docker-compose up --build I got a message:

php-fpm entered RUNNING state, process has stayed up for > than 1 seconds (startsecs).

I red that it's because it runs as a foreground process and I need to use -d instead.

After running docker-compuse up -d I don't get that message.

And the main question is the result are different between those two commands?

1 Answers

From the docs

  • docker-compose up builds, (re)creates, starts, and attaches to containers for a service.
  • docker-compose up -d starts the containers in the background and leaves them running. (this means that if you want to see the logs of the containers you will have to use docker-compose logs -f)
  • docker-compose up --build builds images before starting containers

This similar question: docker-compose up vs docker-compose up --build vs docker-compose build --no-cache mentions that:

if you add the --build option, it is forced to build the images even when not needed.

Related