264

I couldn't figure out what the difference between those.

  • docker-compose up

  • docker-compose up --build

  • docker-compose build --no-cache

Is there any command for upwithout cache?

2 Answers 2

437

The following only builds the images, does not start the containers:

  • docker-compose build

The following builds the images if the images do not exist and starts the containers:

  • docker-compose up

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

  • docker-compose up --build

The following skips the image build process:

  • docker-compose up --no-build

If the images aren't built beforehand, it fails.

The --no-cache option disables the Docker build cache in the image creation process. This is used to cache each layer in the Dockerfile and to speed up the image creation reusing layers (~ Dockerfile lines) previously built for other images that are identical.

6
  • 12
    What does docker-compose up -d ?
    – Horai Nuri
    Jun 16, 2017 at 14:28
  • 39
    That starts the containers in detached mode so will not show any output from them in the console and run them in the background. Jun 19, 2017 at 12:59
  • 4
    Note some options (such as -d) for docker-compose up -d are not in the documentation for just docker-compose. You must look at docs.docker.com/compose/reference/up Aug 26, 2018 at 4:21
  • 6
    @thanks_in_advance --build forces the (re-)build of the images. If you omit the flag and the image exists already, it won't get rebuilt.
    – marsbear
    Dec 22, 2020 at 12:04
  • 2
    so if I run docker-compose up for the very first time on my machine, it will build the image , then run it? Jun 12, 2021 at 6:04
0
  1. docker-compose build when you need to build or rebuild Docker images.

  2. docker-compose up to start and manage containers based on the images you've built or already have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.