From ad2d94ba1c036314390797e25b428fdc5697b8a2 Mon Sep 17 00:00:00 2001 From: Dean Chen <862469039@qq.com> Date: Tue, 18 Aug 2026 10:46:57 +0500 Subject: [PATCH] docs(run): spell out -p syntax and a port range The publish section showed one 127.0.0.1 mapping. Add the [ip:][hostPort:]containerPort form and a host/container range. Signed-off-by: Dean Chen <862469039@qq.com> --- docs/reference/commandline/container_run.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/reference/commandline/container_run.md b/docs/reference/commandline/container_run.md index 1dcc0fd5387b..64c7cb1ff0d8 100644 --- a/docs/reference/commandline/container_run.md +++ b/docs/reference/commandline/container_run.md @@ -521,12 +521,23 @@ $ docker run -t -i --mount type=bind,src=/data,dst=/data busybox sh ### Publish or expose port (-p, --expose) +The `-p` / `--publish` value is `[ip:][hostPort:]containerPort[/protocol]`. +`hostPort` can be a single port or a range (`8080-8081`). + ```console $ docker run -p 127.0.0.1:80:8080/tcp nginx:alpine ``` This binds port `8080` of the container to TCP port `80` on `127.0.0.1` of the -host. You can also specify `udp` and `sctp` ports. The [Networking overview +host. You can also specify `udp` and `sctp` ports. Omit the IP to publish on +all host interfaces (`0.0.0.0`). A range maps host ports onto container ports +in order: + +```console +$ docker run -p 8080-8081:80-81 nginx:alpine +``` + +The [Networking overview page](https://docs.docker.com/network/) explains in detail how to publish ports with Docker.