0
0
Dockerdevops~5 mins

Building images in Compose in Docker - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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.0
Click 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?
Abuild
Bimage
Ccontainer
Dservice
How do you specify a custom Dockerfile name in Compose?
ARename the Dockerfile to Dockerfile.compose
BUse <code>file</code> key at root
CUnder <code>build</code>, use <code>dockerfile</code> key
DUse <code>image</code> key with filename
What does Docker Compose do if the image specified in image does not exist locally and no build is defined?
ABuilds the image automatically
BPulls the image from Docker Hub
CThrows an error and stops
DCreates an empty image
Which command builds images defined in a Docker Compose file before starting containers?
Adocker-compose up
Bdocker-compose run
Cdocker-compose start
Ddocker-compose build
How can you pass build-time variables to a Dockerfile using Compose?
AUsing <code>params</code> under <code>service</code>
BUsing environment variables under <code>environment</code>
CUsing <code>variables</code> key at root
DUsing <code>args</code> under <code>build</code>
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.