Some documentation from reading the docker source code about what -p formats can be given to the docker run -p FORMAT IMAGE
FORMAT can be:
- -p FRONT:BACK which maps FRONT on the host to BACK in the container
- -p :PORT which is the same as -p PORT:PORT
This turns into "PortSpecs": [FRONT, BACK] config
It is related to the EXPOSE command in a dockerfile like EXPOSE FRONT:BACK or more typically EXPOSE BACK
Sources:
- container.go ParseRun() that stores
-poptions inflPortsthen sets it up as the value of a Config PortSpecs key. Later on something eventually calls allocateNetwork() where it walks through PortSpecs and calls allocatePort() - network.go allocatePort() calling parseNat() which is where the syntax above is read
Damn, you say that
-p :PORT which is the same as -p PORT:PORTbut it's acutally same as-p $RANDOM:PORTso it gets bound to random port! (