Recall & Review
beginner
What is port mapping in Docker Compose?
Port mapping connects a port on your computer (host) to a port inside a Docker container, allowing you to access container services from outside.
Click to reveal answer
beginner
How do you define port mapping in a docker-compose.yml file?
Use the
ports key under a service with the format host_port:container_port. For example: ports: - "8080:80"maps host port 8080 to container port 80.
Click to reveal answer
beginner
Why is port mapping important when running containers?
Containers run isolated with their own network. Port mapping lets you reach container apps from your computer or other devices by linking container ports to host ports.
Click to reveal answer
intermediate
What happens if you map the same host port to multiple containers in Compose?
You get a conflict error because only one container can use a host port at a time. You must use different host ports for each container.
Click to reveal answer
intermediate
How do you expose a container port without mapping it to a host port in Compose?
Use the
expose key instead of ports. This makes the port accessible to linked containers but not to the host machine.Click to reveal answer
In docker-compose.yml, how do you map host port 5000 to container port 80?
✗ Incorrect
The correct format is
host_port:container_port. So 5000:80 maps host port 5000 to container port 80.What does the
expose key do in docker-compose?✗ Incorrect
expose shares ports between containers but does not publish them to the host.What error occurs if two services map the same host port in Compose?
✗ Incorrect
Docker Compose throws a port conflict error because only one container can bind to a host port.
Which port is accessible from your computer when you map
8080:80?✗ Incorrect
Host port 8080 is accessible from your computer and forwards traffic to container port 80.
If you want a container port accessible only to other containers, which should you use?
✗ Incorrect
expose shares ports between containers without exposing them to the host.Explain how port mapping works in Docker Compose and why it is useful.
Think about how your computer talks to apps inside containers.
You got /4 concepts.
Describe the difference between the
ports and expose keys in a Compose file.One lets outside world in, the other only shares inside Docker.
You got /4 concepts.