Skip to content

Instantly share code, notes, and snippets.

@dajobe
Created August 27, 2013 18:45
Show Gist options
  • Save dajobe/6357418 to your computer and use it in GitHub Desktop.
Save dajobe/6357418 to your computer and use it in GitHub Desktop.
Docker -p formats

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 -p options in flPorts then 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
@Mart-Bogdan
Copy link

Damn, you say that -p :PORT which is the same as -p PORT:PORT but it's acutally same as -p $RANDOM:PORT so it gets bound to random port! (

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment