Recall & Review
beginner
What does it mean to expose a port in Docker?
Exposing a port means making a port inside the Docker container accessible from the host machine or other containers. It allows communication between the container and the outside world.
Click to reveal answer
beginner
Which Docker command option is used to expose a container port to the host?
The
-p or --publish option is used with docker run to map a container port to a host port, like -p 8080:80.Click to reveal answer
beginner
Explain the syntax
-p 8080:80 in Docker port mapping.It means map port 80 inside the container to port 8080 on the host. So, accessing localhost:8080 on the host reaches port 80 in the container.
Click to reveal answer
intermediate
What is the difference between EXPOSE in Dockerfile and -p in docker run?
EXPOSE in Dockerfile is a hint that the container listens on a port but does not publish it. -p in docker run actually maps the port to the host.Click to reveal answer
beginner
Can you expose multiple ports from a container to the host? How?
Yes, by using multiple
-p options in docker run, for example: -p 8080:80 -p 8443:443 to expose HTTP and HTTPS ports.Click to reveal answer
Which Docker command option exposes a container port to the host?
✗ Incorrect
The
-p option maps container ports to host ports, exposing them.What does
-p 3000:3000 do in docker run?✗ Incorrect
It maps port 3000 on the host to port 3000 inside the container.
What is the purpose of the EXPOSE instruction in a Dockerfile?
✗ Incorrect
EXPOSE is a documentation hint and does not publish ports.
How do you expose multiple ports from a container?
✗ Incorrect
Multiple
-p options map multiple ports to the host.If you run
docker run -p 8080:80, how do you access the container's service?✗ Incorrect
Port 80 in the container is mapped to port 8080 on the host.
Describe how to expose a container port to the host using Docker commands.
Think about how to connect container ports to your computer ports.
You got /3 concepts.
Explain the difference between EXPOSE in Dockerfile and the -p option in docker run.
One is for documentation, the other for actual port access.
You got /3 concepts.