Docker Community Forums

Share and learn in the Docker community.

How does docker know which port to expose?

docker

(Punitnaik) #1

NOTE: This might a be silly question.

I have a Docker file in which there are following lines:

EXPOSE 8080
CMD exec java -Djava.net.preferIPv4Stack=true -jar /srv/my-app.jar 8080

How does docker know to expose the 8080 port of the app and expose it?

Can I specify something like EXPOSE 8080:8081 where the port 8080 will be exposed as 8081? Also, can I specify the protocol?


(David Maze) #2

I’d highly recommend reading the documentation on EXPOSE, which explains how ports get published when a container is run and how to specify UDP/TCP protocol.