What is Docker Compose used for in a development environment?
Docker Compose helps you run and manage multiple containers together easily. It lets you define all your app's services in one file and start them with a single command.
Click to reveal answer
beginner
What file does Docker Compose use to define services?
Docker Compose uses a docker-compose.yml file where you list all your containers, their settings, networks, and volumes.
Click to reveal answer
beginner
How do you start all services defined in a Docker Compose file?
Run the command docker compose up in the folder with your docker-compose.yml. It builds and starts all containers together.
Click to reveal answer
intermediate
Why use volumes in Docker Compose for development?
Volumes let you share code between your computer and the container. This means you can edit files on your computer and see changes immediately inside the container.
Click to reveal answer
beginner
What is the benefit of using Docker Compose over running individual Docker commands?
Docker Compose saves time by managing multiple containers with one file and command. It also keeps your setup organized and easy to share with others.
Click to reveal answer
Which file do you edit to define services in Docker Compose?
ADockerfile
Bdocker-compose.yml
Cdocker.config
Dcompose.json
✗ Incorrect
The docker-compose.yml file is where you define all services, networks, and volumes for Docker Compose.
What command starts all services in Docker Compose?
Adocker compose up
Bdocker compose start
Cdocker run compose
Ddocker build compose
✗ Incorrect
The command docker compose up builds and starts all services defined in the compose file.
Why are volumes useful in a dev environment with Docker Compose?
AThey speed up container startup
BThey reduce container size
CThey allow code changes on host to reflect inside containers immediately
DThey secure the container network
✗ Incorrect
Volumes let you share files between your computer and containers, so code edits update instantly inside the container.
Which of these is NOT a benefit of Docker Compose?
AManage multiple containers with one command
BDefine container setup in one file
CEasily share environment setup
DAutomatically write application code
✗ Incorrect
Docker Compose does not write code; it manages container setups and orchestration.
In Docker Compose, how do you stop and remove containers, networks, and volumes created by docker compose up?
Adocker compose down
Bdocker compose remove
Cdocker compose stop
Ddocker compose clean
✗ Incorrect
The command docker compose down stops and removes containers, networks, and volumes created by docker compose up.
Explain how Docker Compose helps in setting up a development environment with multiple services.
Think about how you would run many containers together without typing many commands.
You got /4 concepts.
Describe the role of volumes in Docker Compose for development and why they are important.
Consider how you want to edit code on your computer and see it run inside the container without delays.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using docker-compose.yml in a development environment?
easy
A. To build Docker images only
B. To define and run multiple containers with one command
C. To replace Docker CLI commands completely
D. To monitor container resource usage
Solution
Step 1: Understand Docker Compose role
Docker Compose uses a YAML file to define multiple containers and their settings.
Step 2: Identify main benefit in dev
It allows running all containers together with a single command, simplifying setup.
Final Answer:
To define and run multiple containers with one command -> Option B
Quick Check:
Compose = multiple containers, one command [OK]
Hint: Compose runs many containers with one file and command [OK]
Common Mistakes:
Thinking Compose only builds images
Believing Compose replaces all Docker CLI commands
Confusing Compose with monitoring tools
2. Which of the following is the correct syntax to expose port 8080 on the host mapped to port 80 in a docker-compose.yml service?
easy
A. ports:
- "80:8080"
B. expose:
- "80:8080"
C. expose:
- "8080:80"
D. ports:
- "8080:80"
Solution
Step 1: Understand ports syntax in Compose
The format is "host_port:container_port" to map host port to container port.
Step 2: Match ports for host 8080 to container 80
To expose container port 80 on host port 8080, use "8080:80" under ports.
Final Answer:
ports:
- "8080:80" -> Option D
Quick Check:
HostPort:ContainerPort = 8080:80 [OK]
Hint: Ports use host:container format [OK]
Common Mistakes:
Reversing host and container ports
Using expose instead of ports for host mapping
Incorrect YAML indentation
3. Given this docker-compose.yml snippet, what will be the effect of the volume configuration?
A. The environment variable for db should use list syntax or key-value mapping consistently
B. The volume pgdata is not defined properly under volumes
C. The command for web service is invalid
D. The environment variable for db uses wrong syntax, should be a list
Solution
Step 1: Inspect YAML syntax in command field
The command: nginx -g 'daemon off;' lacks quotes around the full string, causing YAML to parse it as separate unquoted scalars, leading to a syntax error.
5. You want to set up a development environment with a web app and a database using Docker Compose. The web app needs live code updates from your host machine, and the database should persist data between restarts. Which docker-compose.yml configuration correctly achieves this?