Skip to content

OCI: make /run a tmpfs - #51950

Draft
thaJeztah wants to merge 1 commit into
moby:masterfrom
thaJeztah:run_tmpfs
Draft

thaJeztah wants to merge 1 commit into
moby:masterfrom
thaJeztah:run_tmpfs

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

Our defaults currently don't specify a mount for /run, which means that files inside that directory are persisted in the container's filesystem. This can be problematic in some cases, for example, after a forced shutdown of a container (SIGKILL), pid-files may be left behind (e.g. /run/docker.pid in a DIND container), preventing the docker daemon to be started.

From the FHS spec:

This directory contains system information data describing the system
since it was booted. Files under this directory must be cleared (removed
or truncated as appropriate) at the beginning of the boot process.

From the systemd file hierarchy requirements:

/run must exist as an empty mount point and will automatically be mounted
by systemd with a tmpfs.

In moby, these defaults were added in 9c4570a, but copying the existing defaults before that.

Comparing the defaults with containerd; containerd uses a tmpfs for /run. This mount was added in the initial client implementation; unortunately, there's no additional context in that commit describing it diverging from docker's defaults.

This patch aligns the defaults with containerd and adds /run as a tmpfs, using the same options as containerd's defaults.

With this patch:

docker run --rm alpine sh -c 'mount | grep /run'
tmpfs on /run type tmpfs (rw,nosuid,size=65536k,mode=755)

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

- A picture of a cute animal (not mandatory but encouraged)

Our defaults currently don't specify a mount for `/run`, which means that
files inside that directory are persisted in the container's filesystem.
This can be problematic in some cases, for example, after a forced shutdown
of a container (`SIGKILL`), pid-files may be left behind (e.g. `/run/docker.pid`
in a DIND container), preventing the docker daemon to be started.

From the [FHS spec]:

> This directory contains system information data describing the system
> since it was booted. Files under this directory must be cleared (removed
> or truncated as appropriate) at the beginning of the boot process.

From the [systemd file hierarchy requirements]:

> `/run` must exist as an empty mount point and will automatically be mounted
> by systemd with a tmpfs.

In moby, these defaults were added in 9c4570a,
but copying the [existing defaults] before that.

Comparing the defaults with containerd; containerd uses a tmpfs for `/run`.
This mount was added in the [initial client] implementation; unortunately,
there's no additional context in that commit describing it diverging from
docker's defaults.

This patch aligns the defaults with containerd and adds `/run` as a tmpfs,
using the same options as [containerd's defaults].

With this patch:

    docker run --rm alpine sh -c 'mount | grep /run'
    tmpfs on /run type tmpfs (rw,nosuid,size=65536k,mode=755)

[existing defaults]: https://github.com/moby/moby/blob/9c4570a958df42d1ad19364b1a8da55b891d850a/daemon/execdriver/native/template/default_template_linux.go#L46-L85
[FHS spec]: https://specifications.freedesktop.org/fhs/latest/run.html
[systemd file hierarchy requirements]: https://github.com/systemd/systemd/blob/v259/docs/SYSTEMD_FILE_HIERARCHY_REQUIREMENTS.md#systemd-file-hierarchy-requirements
[initial client]: containerd/containerd@d0e5732
[containerd's defaults]: https://github.com/containerd/containerd/blob/v2.2.1/pkg/oci/mounts.go#L63-L68

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Comment on lines +107 to +112
{
Destination: "/run",
Type: "tmpfs",
Source: "tmpfs",
Options: []string{"nosuid", "strictatime", "mode=755", "size=65536k"},
},

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW; checking on a Ubuntu 24.04 droplet on DigitalOcean; mount options there are;

tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=98468k,mode=755,inode64)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably add nodev (perhaps in containerd as well). Perhaps if we want to harden things, we could add nr_inodes with some sensible limit (4k? 8k? 16k?); https://www.man7.org/linux/man-pages/man5/tmpfs.5.html

@thaJeztah

Copy link
Copy Markdown
Member Author

Some failures look related, but could be poorly written tests (or test plugin binary) assuming that /run is persisted;

=== FAIL: amd64.docker.docker.integration.plugin.logging TestContinueAfterPluginCrash (9.84s)
    logging_linux_test.go:44: assertion failed: error is not nil: Error response from daemon: failed to create task for container: failed to initialize logging driver: error creating logger: LogDriver.StartLogging: open /run/docker/logging/0b78d0a0e43ca08e3a8b4b4bb8ae08448704fe85004ab623d055527e25503bb0: no such file or directory

=== FAIL: amd64.docker.docker.integration.plugin.logging TestReadPluginNoRead/default (2.90s)
    read_test.go:67: assertion failed: error is not nil: Error response from daemon: failed to create task for container: failed to initialize logging driver: error creating logger: open /run/docker/logging/6921c577e1cd7b43db7660abb820d3f768b2b9b7f1e85ee3b3e52f5ca3e63c47: no such file or directory
    --- FAIL: TestReadPluginNoRead/default (2.90s)

=== FAIL: amd64.docker.docker.integration.plugin.logging TestReadPluginNoRead/disabled_caching (1.85s)
    read_test.go:67: assertion failed: error is not nil: Error response from daemon: failed to create task for container: failed to initialize logging driver: error creating logger: open /run/docker/logging/4f713a8c0ada038773b2466b46a8b295b5453800e1926ed5982eac8bee1d2d13: no such file or directory
    --- FAIL: TestReadPluginNoRead/disabled_caching (1.85s)

=== FAIL: amd64.docker.docker.integration.plugin.logging TestReadPluginNoRead/explicitly_enabled_caching (1.84s)
    read_test.go:67: assertion failed: error is not nil: Error response from daemon: failed to create task for container: failed to initialize logging driver: error creating logger: open /run/docker/logging/9288e45013b5017012cee54d574a49c721b142bf0b84e2f5eb9bc5aad6136294: no such file or directory
    --- FAIL: TestReadPluginNoRead/explicitly_enabled_caching (1.84s)

=== FAIL: amd64.docker.docker.integration.plugin.logging TestReadPluginNoRead (16.32s)

@thaJeztah

thaJeztah commented Jan 28, 2026 •

Copy link
Copy Markdown
Member Author

Hm.. ok so this may be a fun one; looks like this (at least at a glance) is where things go wrong; this code;

if err := os.MkdirAll(logRoot, 0o700); err != nil {

Creates a path on the host, but within the plugin's rootfs. For example, in the test that's failing, it creates;

/go/src/github.com/docker/docker/bundles/test-integration/TestReadPluginNoRead/d601c72615b5d/root/plugins/1654ca17c1a626294b4e96f0a66acd378d2d00f2ba007b0b3e4bd656e0826b5a/rootfs/run/docker/logging

Or, if it would be a normal path (/var/lib/docker);

/var/lib/docker/plugins/1654ca17c1a626294b4e96f0a66acd378d2d00f2ba007b0b3e4bd656e0826b5a/rootfs/run/docker/logging

This path is used for the plugin's fifo, which also gets created first;

fifoPath: filepath.Join(logRoot, id),

stream, err := openPluginStream(a)

func openPluginStream(a *pluginAdapter) (io.WriteCloser, error) {
// Make sure to also open with read (in addition to write) to avoid broken pipe errors on plugin failure.
// It is up to the plugin to keep track of pipes that it should re-attach to, however.
// If the plugin doesn't open for reads, then the container will block once the pipe is full.
f, err := fifo.OpenFifo(context.Background(), a.fifoPath, unix.O_RDWR|unix.O_CREAT|unix.O_NONBLOCK, 0o700)
if err != nil {
return nil, errors.Wrapf(err, "error creating i/o pipe for log plugin: %s", a.Name())
}
return f, nil
}

/go/src/github.com/docker/docker/bundles/test-integration/TestReadPluginNoRead/d601c72615b5d/root/plugins/1654ca17c1a626294b4e96f0a66acd378d2d00f2ba007b0b3e4bd656e0826b5a/rootfs/run/docker/logging/88c9bd2922ea82e67cfbf93565d3e62c7aafd14ee8f9241b597a3c46bd557945

Or:

/var/lib/docker/plugins/1654ca17c1a626294b4e96f0a66acd378d2d00f2ba007b0b3e4bd656e0826b5a/rootfs/run/docker/logging/88c9bd2922ea82e67cfbf93565d3e62c7aafd14ee8f9241b597a3c46bd557945

And this path is missing;

time="2026-01-28T08:51:28.362724136Z" level=debug msg="error response for POST request" error-response="failed to create task for container: failed to initialize logging driver: error creating logger: open /run/docker/logging/21a71cb6d72506281fd26d9a0bc4f54348d2d159e1af1d3e0e7d54ec9c03289d: no such file or directory" method=POST module=api request-url=/v1.53/containers/8f1aa5e1f77ed16e21a19c7aabf1c80644711cc46e908463874547da4be2118f/start status=400 vars="map[name:8f1aa5e1f77ed16e21a19c7aabf1c80644711cc46e908463874547da4be2118f version:1.53]"
time="2026-01-28T08:51:29.262734428Z" level=debug msg="error response for POST request" error-response="failed to create task for container: failed to initialize logging driver: error creating logger: open /run/docker/logging/30776baccd64cc33f61aa8dbc20b221b49e76e50e3d198d761719ebc6d1295d8: no such file or directory" method=POST module=api request-url=/v1.53/containers/e96a8de27373598ea0331ec5c1c9fb9d5c7902b5f59e1dbf4cf21747399a0b1f/start status=400 vars="map[name:e96a8de27373598ea0331ec5c1c9fb9d5c7902b5f59e1dbf4cf21747399a0b1f version:1.53]"
time="2026-01-28T08:51:30.034454845Z" level=debug msg="error response for POST request" error-response="failed to create task for container: failed to initialize logging driver: error creating logger: open /run/docker/logging/88c9bd2922ea82e67cfbf93565d3e62c7aafd14ee8f9241b597a3c46bd557945: no such file or directory" method=POST module=api request-url=/v1.53/containers/022815ba1591db5df3cb1a2fe8f0cc9524903d91754e18b9e92ae1b00db12c8e/start status=400 vars="map[name:022815ba1591db5df3cb1a2fe8f0cc9524903d91754e18b9e92ae1b00db12c8e version:1.53]"

@tianon

tianon commented Jan 29, 2026 •

Copy link
Copy Markdown
Member

Trying to summarize my thoughts from today's call in a succinct way (fingers crossed I'm successful):

I'm very sympathetic to this change and would personally enjoy it.

However, we've got 13 years of historical usage where the tmpfs does not exist, and we don't have either a way for users / image authors to "opt out" of this tmpfs, nor do we have a way for them to pre-create necessary directories (see #26528 for a concrete historical example where Red Hat apparently applied a patch similar to this and broke someone). While that's fine for new software (it could just be updated to pre-create the directory, after all), older software does not necessarily have that luxury.

The best way to phrase my concerns about this change is that /run is a userspace convention, not an explicit kernel interface (unlike /dev, /proc, and /sys - granted their mount location is also convention, but we have to provide them somewhere and they are explicit kernel interfaces so following the convention is sane).

For example, it would be completely reasonable to have a full userspace that doesn't use or care about /run at all, or worse, uses /run for something that's not temporary.

So in short, while I personally would enjoy this change, I'm officially a -1 on making it. 🖤

(perhaps instead we could work to add some way for image authors to specifically request that a given directory be a tmpfs? some kind of annotation or label or something similar to volumes, but useful instead of just annoying?)

edit: thanks to Eric Curtin for helping find #8478 which is the ref I was really looking for when I found the one linked above

@thaJeztah thaJeztah moved this from New to Parked in 🔦 Maintainer spotlight Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/daemon Core Engine

Projects

Status: Parked

Development

Successfully merging this pull request may close these issues.

2 participants