beginners/dockerfile/Lab#11_EXPOSE_instruction.md
The EXPOSE instruction expose a port, the protocol can be UDP or TCP associated with the indicated port, default is TCP with no specification. The EXPOSE won't be able to map the ports on the host machine. Regardless of the EXPOSE settings, EXPOSE port can be override using <b>-p</b> flag while starting the container.
Dockerfile
FROM nginx:alpine
LABEL maintainer="Collabnix"
EXPOSE 80/tcp
EXPOSE 80/udp
CMD [ "nginx","-g","daemon off;" ]
$ docker build -t expose:v1 .
$ docker container run --rm -d --name expose-inst expose:v1
$ docker image inspect --format={{.ContainerConfig.ExposedPorts}} expose:v1
We can publish all EXPOSE port using <b>-P</b> flag.
$ docker container run --rm -P -d --name expose-inst-Publish expose:v1
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
24983e09bd86 expose:v1 "nginx -g 'daemon of…" 46 seconds ago Up 45 seconds 0.0.0.0:32768->80/tcp, 0.0.0.0:32768->80/udp expose-inst-Publish
Next >> Lab #12: LABEL instruction