EXPOSE <port> [<port>...]
The EXPOSE
instruction informs Docker that the container listens on the specified network ports at runtime. EXPOSE
does NOT make the ports of the container accessible to the host. To do that, you must use either the -p
flag to publish a range of ports or the -P
flag to publish all of the exposed ports. These flags are used in the docker run [OPTIONS] IMAGE [COMMAND][ARG...]
to expose the port to the host. You can expose one port number and publish it externally under another number.
docker run -p 2500:80 <image name>
This command will create a container with the name <image> and bind the container’s port 80 to the host machine’s port 2500.
To set up port redirection on the host system, see using the -P
flag. The Docker network feature supports creating networks without the need to expose ports within the network, for detailed information see the overview of this feature).