A Docker image contains the code used to create a Docker container, such as creating a Nginx web server, or a mySQL server, or a home grown app, and the list goes on. In this way, an image is like a template used to create a container. An image is kind of like a virtual machine, but much more light weight, using significantly less storage a memory (containers are usually megabytes in size).
When building an image using the docker build command and a Dockerfile, the EXPOSE option can be used to define in ports that are meant to be used by the application or service in the image.
This does NOT add a rule to iptables to allow the port, meaning you will still need to use the -p or --publish option when using the docker run command to create the container from the image.
In this example, TCP port 8080 will be exposed in the image. If TCP or UDP are not included, the TCP protocol will be used.
FROM centos:latest EXPOSE 8080
Or, the TCP protocol can be included.
FROM centos:latest EXPOSE 8080/tcp
FROM centos:latest EXPOSE 8080/udp
And here is how you would expose multiple ports.
FROM centos:latest EXPOSE 8080/tcp 8080/udp 8081