Recall & Review
beginner
What is the purpose of the
build key in a Docker Compose file?The
build key tells Docker Compose to create a Docker image from a Dockerfile before starting the container.Click to reveal answer
intermediate
How do you specify the path to a Dockerfile in a Compose file?
Use
build: with a context for the folder and dockerfile for the file name, like:<br>build: context: ./app dockerfile: Dockerfile.dev
Click to reveal answer
beginner
What happens if you run
docker-compose up and the image does not exist?Docker Compose will automatically build the image using the Dockerfile specified under the
build key before starting the container.Click to reveal answer
intermediate
Can you pass build arguments in Docker Compose? How?
Yes, you can pass build arguments using the
args key under build. For example:<br>build:
context: .
args:
VERSION: 1.0Click to reveal answer
beginner
What is the difference between
image and build in a Compose service?image specifies an existing image to use, while build tells Compose to create an image from a Dockerfile before running the container.Click to reveal answer
In a Docker Compose file, which key is used to build an image from a Dockerfile?
✗ Incorrect
The
build key tells Compose to build an image from a Dockerfile.How do you specify a custom Dockerfile name in Compose?
✗ Incorrect
You specify the Dockerfile name with the
dockerfile key inside the build section.What does Docker Compose do if the image specified in
image does not exist locally and no build is defined?✗ Incorrect
Docker Compose tries to pull the image from a registry like Docker Hub if it is not found locally.
Which command builds images defined in a Docker Compose file before starting containers?
✗ Incorrect
docker-compose up builds images if needed and starts containers.How can you pass build-time variables to a Dockerfile using Compose?
✗ Incorrect
Build arguments are passed with the
args key inside the build section.Explain how Docker Compose builds images using the
build key and what options you can specify under it.Think about how you tell Compose where the Dockerfile is and how to customize the build.
You got /4 concepts.
Describe the difference between using
image and build in a Docker Compose service.Consider when you want to use a ready image versus creating your own.
You got /4 concepts.