Docker Community Forums

Share and learn in the Docker community.

Can you Publish a port in a dockerfile ? no!


(Ralph Kincade) #1

I am seeing this

Publishing a specific port with -p I know that I can do this at RUNTIME but can I do this in Dockerfile?

can you confirm thsi ?

Instead of merely offering up a port, you can explicitly bind a port or group of ports from container to host using the -p flag. Note this is the lowercase p, not uppercase. Because this configuration does depend on the host, t**here is no equivalent instruction allowed in the Dockerfile; it is a runtime configuration only**. The -p flag can take a few different formats:

from this site

https://www.ctl.io/developers/blog/post/docker-networking-rules/