Skip to content

Commit 571d235

Browse files
memoryMisty Stanley-Jones
authored and
Misty Stanley-Jones
committed
Suggest passing --no-log-init to adduser (#3413)
Running `useradd` without `--no-log-init` risks triggering a resource exhaustion issue: moby/moby#15585 moby/moby#5419 golang/go#13548
1 parent 40db188 commit 571d235

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

engine/userguide/eng-image/dockerfile_best-practices.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,20 @@ parts of your image.
513513

514514
If a service can run without privileges, use `USER` to change to a non-root
515515
user. Start by creating the user and group in the `Dockerfile` with something
516-
like `RUN groupadd -r postgres && useradd -r -g postgres postgres`.
516+
like `RUN groupadd -r postgres && useradd --no-log-init -r -g postgres postgres`.
517517

518518
> **Note**: Users and groups in an image get a non-deterministic
519519
> UID/GID in that the “next” UID/GID gets assigned regardless of image
520520
> rebuilds. So, if it’s critical, you should assign an explicit UID/GID.
521521
522+
> **Note**: Due to an [unresolved bug](https://github.com/golang/go/issues/13548)
523+
> in the Go archive/tar package's handling of sparse files, attempting to
524+
> create a user with a sufficiently large UID inside a Docker container can
525+
> lead to disk exhaustion as `/var/log/faillog` in the container layer is
526+
> filled with NUL (\0) characters. Passing the `--no-log-init` flag to
527+
> useradd works around this issue. The Debian/Ubuntu `adduser` wrapper
528+
> does not support the `--no-log-init` flag and should be avoided.
529+
522530
You should avoid installing or using `sudo` since it has unpredictable TTY and
523531
signal-forwarding behavior that can cause more problems than it solves. If
524532
you absolutely need functionality similar to `sudo` (e.g., initializing the

0 commit comments

Comments
 (0)