What is the EXPOSE instruction good for in Docker?
Experience Level: Senior
Tags: Docker
Answer
The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. You can specify whether the port listens on TCP or UDP, and the default is TCP if the protocol is not specified.
The EXPOSE instruction does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published. To actually publish the port when running the container, use the -p flag on docker run to publish and map one or more ports, or the -P flag to publish all exposed ports and map them to high-order ports.
By default, EXPOSE assumes TCP. You can also specify UDP.
Example:
EXPOSE 80/udp
Related Docker job interview questions
How many CMD instructions can be in a Dockerfile?
Docker SeniorWhat is the CMD instruction good for in Docker?
Docker SeniorWhat is the VOLUME instruction good for in Docker?
Docker SeniorCan the WORKDIR instruction resolve environment variables in Docker?
Docker SeniorWhat is the WORKDIR instruction good for in Docker?
Docker Senior