How does docker know which port to expose?

NOTE: This might a be silly question.

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

CMD exec java -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?

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.