0
0
Dockerdevops~5 mins

EXPOSE instruction for ports in Docker - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the EXPOSE instruction do in a Dockerfile?
It tells Docker which ports the container will listen on at runtime. It acts as documentation and helps Docker map ports when running containers.
Click to reveal answer
beginner
Does the EXPOSE instruction publish ports to the host machine automatically?
No. EXPOSE only documents the ports. To make ports accessible outside the container, you must use the -p or --publish option with docker run.
Click to reveal answer
intermediate
How do you expose multiple ports in a Dockerfile?
You can use multiple EXPOSE instructions, one per port, or list multiple ports separated by spaces in a single EXPOSE instruction.
Click to reveal answer
beginner
Example: What does this line do? EXPOSE 80 443
It declares that the container listens on ports 80 and 443. This helps users know which ports to map when running the container.
Click to reveal answer
intermediate
Can EXPOSE specify the protocol (TCP/UDP) for a port?
Yes. You can specify the protocol by adding /tcp or /udp after the port number, like EXPOSE 53/udp. If omitted, TCP is assumed.
Click to reveal answer
What is the main purpose of the EXPOSE instruction in a Dockerfile?
ATo set environment variables
BTo automatically publish ports to the host
CTo build the container image
DTo document which ports the container listens on
How do you make a container port accessible from the host machine?
AUse the EXPOSE instruction in the Dockerfile
BUse the -p or --publish option with docker run
CAdd the port to the CMD instruction
DSet the port in the ENV instruction
Which of these is a valid way to expose ports 80 and 443 in a Dockerfile?
AEXPOSE 80 443
BEXPOSE 80,443
CEXPOSE 80; EXPOSE 443
DEXPOSE 80:443
What protocol does EXPOSE assume if none is specified?
AUDP
BHTTP
CTCP
DFTP
Which command publishes container port 8080 to host port 80?
Adocker run -p 80:8080 image
Bdocker run -p 8080:80 image
Cdocker run --expose 80:8080 image
Ddocker run --publish 8080 image
Explain the role of the EXPOSE instruction in a Dockerfile and how it relates to port publishing.
Think about what EXPOSE tells Docker and what it does not do.
You got /3 concepts.
    Describe how to expose multiple ports and specify protocols using the EXPOSE instruction.
    Consider how to list ports and add protocol details.
    You got /3 concepts.