Matt C.
Matt C.

Reputation: 3310

What is the difference between lowercase "-p" and uppercase "-P" arguments in docker run command?

When running a docker container, I've notice that you can provide a lowercase -p or uppercase -P argument. I understand that the -p/-P flags are involved in publishing ports from the docker container to make them available to services outside of Docker, or to Docker containers which are not connected to the container’s network. However I cannot seem to find a clear explanation on the difference between a lowercase -p and a capital -P.

I've googled, searched SO, and searched through Docker docs, but haven't found the clear answer to this question.

Upvotes: 1

Views: 1601

Answers (2)

Saeed
Saeed

Reputation: 4125

According to Docker Run Docs:

-P         : Publish all exposed ports to the host interfaces
-p=[]      : Publish a container's port or a range of ports to the host
               format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort
               Both hostPort and containerPort can be specified as a
               range of ports. When specifying ranges for both, the
               number of container ports in the range must match the
               number of host ports in the range, for example:
                   -p 1234-1236:1234-1236/tcp

Upvotes: 1

shree.pat18
shree.pat18

Reputation: 21757

From the documentation:

The -P option publishes all the ports to the host interfaces. Docker binds each exposed port to a random port on the host. The range of ports are within an ephemeral port range defined by /proc/sys/net/ipv4/ip_local_port_range.

Use the -p flag to explicitly map a single port or range of ports.

Upvotes: 4

Related Questions