Site Tools


wiki:docker-ports

Table of Contents

Docker Ports

Port mapping connects container ports to host ports. Use docker run -p <host>:<container> to map. Multiple -p flags map multiple ports. EXPOSE is a Dockerfile instruction that documents ports but doesn't actually publish them. Containers on the same network reach each other by name without explicit port mapping.

$ docker run -p 8080:3000 myapp              # host port 8080 -> container port 3000
$ docker run -p 8080:3000 -p 9000:5000 myapp # map multiple ports
$ docker run -p 127.0.0.1:8080:3000 myapp    # bind to localhost only
$ docker port <container>                    # show port mappings

Port mapping is only needed to access the container from outside the host. If you're using Docker networks, containers can reach each other directly by service name without port mapping. EXPOSE in a Dockerfile is documentation only; it doesn't enforce port publishing. You must use -p at runtime to actually publish ports to the host.

wiki/docker-ports.md · Last modified: by 127.0.0.1