Skip to content

Commit 2ae903e

Browse files
authored
Merge pull request #4929 from dvdksn/privileged-flag
docs: clarify what the --privileged flag does
2 parents 5931a2f + 9349f58 commit 2ae903e

3 files changed

Lines changed: 42 additions & 12 deletions

File tree

docs/reference/commandline/container_exec.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Execute a command in a running container
1616
| [`-e`](#env), [`--env`](#env) | `list` | | Set environment variables |
1717
| `--env-file` | `list` | | Read in a file of environment variables |
1818
| `-i`, `--interactive` | | | Keep STDIN open even if not attached |
19-
| `--privileged` | | | Give extended privileges to the command |
19+
| [`--privileged`](#privileged) | | | Give extended privileges to the command |
2020
| `-t`, `--tty` | | | Allocate a pseudo-TTY |
2121
| `-u`, `--user` | `string` | | Username or UID (format: `<name\|uid>[:<group\|gid>]`) |
2222
| [`-w`](#workdir), [`--workdir`](#workdir) | `string` | | Working directory inside the container |
@@ -96,6 +96,10 @@ VAR_B=2
9696
HOME=/root
9797
```
9898

99+
### <a name="privileged"></a> Escalate container privileges (--privileged)
100+
101+
See [`docker run --privileged`](container_run.md#privileged).
102+
99103
### <a name="workdir"></a> Set the working directory for the exec process (--workdir, -w)
100104

101105
By default `docker exec` command runs in the same working directory set when

docs/reference/commandline/container_run.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,37 @@ are broken into multiple containers, you might need to share the IPC mechanisms
341341
of the containers, using `"shareable"` mode for the main (i.e. "donor")
342342
container, and `"container:<donor-name-or-ID>"` for other containers.
343343

344-
### <a name="privileged"></a> Full container capabilities (--privileged)
344+
### <a name="privileged"></a> Escalate container privileges (--privileged)
345+
346+
The `--privileged` flag gives the following capabilities to a container:
347+
348+
- Enables all Linux kernel capabilities
349+
- Disables the default seccomp profile
350+
- Disables the default AppArmor profile
351+
- Disables the SELinux process label
352+
- Grants access to all host devices
353+
- Makes `/sys` read-write
354+
- Makes cgroups mounts read-write
355+
356+
In other words, the container can then do almost everything that the host can
357+
do. This flag exists to allow special use-cases, like running Docker within
358+
Docker.
359+
360+
> **Warning**
361+
>
362+
> Use the `--privileged` flag with caution.
363+
> A container with `--privileged` is not a securely sandboxed process.
364+
> Containers in this mode can get a root shell on the host
365+
> and take control over the system.
366+
>
367+
> For most use cases, this flag should not be the preferred solution.
368+
> If your container requires escalated privileges,
369+
> you should prefer to explicitly grant the necessary permissions,
370+
> for example by adding individual kernel capabilities with `--cap-add`.
371+
>
372+
> For more information, see
373+
> [Runtime privilege and Linux capabilities](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities)
374+
{ .warning }
345375

346376
The following example doesn't work, because by default, Docker drops most
347377
potentially dangerous kernel capabilities, including `CAP_SYS_ADMIN ` (which is
@@ -363,11 +393,6 @@ Filesystem Size Used Avail Use% Mounted on
363393
none 1.9G 0 1.9G 0% /mnt
364394
```
365395

366-
The `--privileged` flag gives all capabilities to the container, and it also
367-
lifts all the limitations enforced by the `device` cgroup controller. In other
368-
words, the container can then do almost everything that the host can do. This
369-
flag exists to allow special use-cases, like running Docker within Docker.
370-
371396
### <a name="workdir"></a> Set working directory (-w, --workdir)
372397

373398
```console

docs/reference/run.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -813,11 +813,12 @@ by default a container is not allowed to access any devices, but a
813813
the documentation on [cgroups devices](https://www.kernel.org/doc/Documentation/cgroup-v1/devices.txt)).
814814

815815
The `--privileged` flag gives all capabilities to the container. When the operator
816-
executes `docker run --privileged`, Docker will enable access to all devices on
817-
the host as well as set some configuration in AppArmor or SELinux to allow the
818-
container nearly all the same access to the host as processes running outside
819-
containers on the host. Additional information about running with `--privileged`
820-
is available on the [Docker Blog](https://www.docker.com/blog/docker-can-now-run-within-docker/).
816+
executes `docker run --privileged`, Docker enables access to all devices on
817+
the host, and reconfigures AppArmor or SELinux to allow the container
818+
nearly all the same access to the host as processes running outside
819+
containers on the host. Use this flag with caution.
820+
For more information about the `--privileged` flag, see the
821+
[`docker run` reference](https://docs.docker.com/reference/cli/docker/container/run/#privileged).
821822

822823
If you want to limit access to a specific device or devices you can use
823824
the `--device` flag. It allows you to specify one or more devices that

0 commit comments

Comments
 (0)