Skip to content

Remove need to run shim inside Exec container #4989

Closed

Description

@sipsma

We currently run the shim both outside the container (to reconfigure the runc bundle) and inside exec containers, which makes it straightforward to redirect stdout/stderr, serve nested sessions, etc. It's the pid 1 and spawns the actual user process as a subchild.

However, this can cause problems for programs that insist on being pid 1 such as systemd.

We can instead run the shim completely outside the container. This will require at least:

  1. Still handling stdout/stderr file redirects correctly, including when they are to submounts.
    • Most promising path here may be to use /proc/<pid>/root to get access to the full filesystem the container sees.
  2. Serving nested sessions
    • This will likely require nsenter'ing into the network namespace of the container
    • It also requires that the session reads and writes files from under /proc/<pid>/root for all relevant APIs, including file sync. File sync specifically can likely be addressed via some tweaks to our callback here.

There might be more than that, but that's what immediately comes to mind.

One annoying part of this is that we currently use runc run, which combines create/start/stop into a single operation. But to get the container pid and setup file access in a non-racey way we'll probably need to split out into separate create/start/stop operations.


Not a requirement, but we could also consider moving the shim to a different approach as part of this if it makes any of this easier. Two ideas:

  1. Switch to a containerd backend and convert our shim to be an actual containerd shim
  2. Implement the shim functionality as a custom buildkit executor, which is possible now that we are using buildkit as a library with in our own custom engine binary.

2 in particular is intriguing in that it may open more avenues such as adding custom session attachables, but it has the major potential downside of us needing to copy a lot of code from buildkit, which makes maintaining it harder in the long run.

We can also consider upstreaming at least the stdout/stderr handling, but I think the nested session might be too dagger specific to upstream unless we can think of a generic way of modeling it.

Activity

  1. locked and limited conversation to collaborators on Mar 24, 2026
  2. converted this issue into a discussion #12411 on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions