-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: refactor cli run reference #4615
Changes from 1 commit
2f48f41
fad227d
03dc883
d66fe78
ff62bf4
5dd6e9a
7362097
dbffa0d
32189ca
f984444
92c664b
9e75a4c
72df196
4a6cde8
c695ad9
b01e287
3eeac20
7585d66
5ede4c8
52716c8
259aa90
4a84514
2e394eb
f8dd8f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,7 @@ Create and run a new container from an image | |
| `--platform` | `string` | | Set platform if server is multi-platform capable | | ||
| [`--privileged`](#privileged) | | | Give extended privileges to this container | | ||
| [`-p`](#publish), [`--publish`](#publish) | `list` | | Publish a container's port(s) to the host | | ||
| `-P`, `--publish-all` | | | Publish all exposed ports to random ports | | ||
| [`-P`](#publish-all), [`--publish-all`](#publish-all) | | | Publish all exposed ports to random ports | | ||
| [`--pull`](#pull) | `string` | `missing` | Pull image before running (`always`, `missing`, `never`) | | ||
| `-q`, `--quiet` | | | Suppress the pull output | | ||
| [`--read-only`](#read-only) | | | Mount the container's root filesystem as read only | | ||
|
@@ -483,26 +483,47 @@ $ docker run -t -i --mount type=bind,src=/data,dst=/data busybox sh | |
### <a name="publish"></a> Publish or expose port (-p, --expose) | ||
|
||
```console | ||
$ docker run -p 127.0.0.1:80:8080/tcp ubuntu bash | ||
$ 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 | ||
machine. You can also specify `udp` and `sctp` ports. | ||
The [Docker User Guide](https://docs.docker.com/network/links/) | ||
explains in detail how to use ports in Docker. | ||
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 | ||
page](https://docs.docker.com/network/) explains in detail how to publish ports | ||
with Docker. | ||
|
||
Note that ports which are not bound to the host (i.e., `-p 80:80` instead of | ||
`-p 127.0.0.1:80:80`) are externally accessible. This also applies if | ||
you configured UFW to block this specific port, as Docker manages its | ||
own iptables rules. [Read more](https://docs.docker.com/network/iptables/) | ||
> **Note** | ||
> | ||
> If you don't specify an IP address (i.e., `-p 80:80` instead of `-p | ||
> 127.0.0.1:80:80`) when publishing a container's ports, Docker publishes the | ||
> port on all interfaces (address `0.0.0.0`) by default. These ports are | ||
> externally accessible. This also applies if you configured UFW to block this | ||
> specific port, as Docker manages its own iptables rules. [Read | ||
> more](https://docs.docker.com/network/packet-filtering-firewalls/) | ||
|
||
```console | ||
$ docker run --expose 80 ubuntu bash | ||
$ docker run --expose 80 nginx:alpine | ||
``` | ||
|
||
This exposes port `80` of the container without publishing the port to the host | ||
system's interfaces. | ||
|
||
### <a name="publish-all"></a> Publish all exposed ports (-P, --publish-all) | ||
|
||
```console | ||
$ docker run -P nginx:alpine | ||
``` | ||
|
||
The `-P`, or `--publish-all`, flag publishes all the exposed ports to the host. | ||
Docker binds each exposed port to a random port on the host. | ||
|
||
The `-P` flag only publishes port numbers that are explicitly flagged as | ||
exposed, either using the Dockerfile `EXPOSE` instruction or the `--expose` | ||
flag for the `docker run` command. | ||
|
||
The range of ports are within an *ephemeral port range* defined by | ||
`/proc/sys/net/ipv4/ip_local_port_range`. Use the `-p` flag to explicitly map a | ||
single port or range of ports. | ||
Comment on lines
+523
to
+525
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Sorry for being picky on that one, but I know it's been troublesome in the past, so trying to preserve the information. Related to that, I need to check with @akerouanton and @robmry what options we currently have to influence these; I know there's some ports used by Windows itself that are within the ephemeral port range, and I know there's been issues with Swarm services picking their own range(s). Perhaps we need configuration options for this on the daemon (not just a "range", but also options to exclude range(s) or individual ports from being used). |
||
|
||
### <a name="pull"></a> Set the pull policy (--pull) | ||
|
||
Use the `--pull` flag to set the image pull policy when creating (and running) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also for a follow-up; we need to make a pass at reviewing examples like this in light of IPv6 (i.e., both
127.0.0.x
and::1
becoming more relevant). /cc @akerouanton @robmry