DELAPARRA
Index
Color
NL
Category: Docker

port mapping

Explained by Updated

What is port mapping?

port mapping: Publishing a container port to a host port so external clients can reach it. The -p HOST:CONTAINER flag. Port mapping publishes a port inside a container on a port of the host machine. docker run -p 8080:80 nginx makes the web server inside the container, listening on port 80, reachable at port 8080 on your computer.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about port mapping

How is port mapping used in practice?

The format is always host port first, then container port. You can also bind to a specific address, such as -p 127.0.0.1:8080:80, so the port is only reachable from the machine itself.

What should you keep in mind with port mapping?

That last form matters on servers. By default, Docker publishes ports on all network interfaces and adds firewall rules that can bypass tools like UFW. A database published with -p 3306:3306 on a public server may be reachable from the whole internet. Publish only what needs to be public, and bind internal services to 127.0.0.1 or leave them unpublished.

What does an example of port mapping look like?

docker run -p 8080:80 nginx

At a glance

CategoryDocker
Explained by
Updated

More Docker terms

All terms starting with P

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.