Docker Concepts

Docker port publishing

For ordinary bridge/NAT networking, forwards a host port to a container port. An omitted host address usually binds all addresses; explicitly choose loopback for local development. Engine before 28.0.0 has a documented same-L2 localhost exposure caveat. Publication is not authentication. Use an approved isolated VM, a preloaded reviewed fixture and a free host port. The lab requires a supported patched Engine at or above 28.0.0, isolated VM and ordinary NAT without direct-routing exceptions. A loopback binding does not restrict every possible path to the container.

Formal Syntax & Structure

docker syntaxdocker
docker run -p HOST_IP:HOST_PORT:CONTAINER_PORT IMAGE

Parameters & Attributes

NameTypeDescription
HOST_IPstringHost-side address; use 127.0.0.1 for IPv4 loopback.
HOST_PORTintegerHost-side port; empty requests allocation.
CONTAINER_PORTintegerDestination service port inside the container.

Working Example

Example Snippetdocker
docker run -d --pull=never --name bm-v05-ref -p 127.0.0.1::8080 busybox:1.37 sh -c 'mkdir -p /tmp/www && printf "ByteMind network lab\n" > /tmp/www/index.html && exec httpd -f -p 8080 -h /tmp/www'docker port bm-v05-ref 8080/tcpdocker stop bm-v05-refdocker rm bm-v05-ref
Docker Reference