-p
argument, for example:nginx
) available on port 80 of localhost
. In this example, thehost and container ports are the same. What if you need to specify a differenthost port? If, for example, you already have something running on port 80 ofyour host machine, you can connect the container to a different port:localhost:8000
are sent to port 80 in the container. Thesyntax for -p
is HOST_PORT:CLIENT_PORT
.docker0
interface on the host. This interface is actually within the virtualmachine.host.docker.internal
which resolves to the internal IP address used by thehost. This is for development purpose and will not work in a production environment outside of Docker Desktop for Mac.gateway.docker.internal
.python -m http.server 8000
python -m SimpleHTTPServer 8000
.curl
, and try to connect to the host using the following commands:localhost
; --publish
, -p
, or -P
all work.Ports exposed from Linux are forwarded to the host.nginx
webserver shown in Getting Startedis an example of this.80
on thecontainer to port 8000
on the host:-P
flag. For example, the following commandstarts a container (in detached mode) and the -P
exposes all ports on thecontainer to random ports on the host.docker run
.