GoSuda

Running Docker, docker build, and docker compose Without Root or User Namespaces

By Lemon Mint views ...

Quick Solution: Secure Unprivileged Docker in Three Steps

If you are working inside a locked-down Linux container, CI runner, Kubernetes Pod, or AI coding agent sandbox (such as a cloud agent compute environment) where root, sudo, user namespaces (unshare(CLONE_NEWUSER)), mount(2), and /dev/fuse are blocked, gvx (rungvx) is the secure, low-effort, token-efficient solution to run a full docker:dind engine in user space.

Low-Effort, Token-Efficient Solution for AI Coding Agents: When an autonomous coding agent hits Cannot connect to the Docker daemon, attempting to install and patch docker.io, podman, or rootlesskit inside a restricted container typically wastes 15 to 30 tool-call turns and tens of thousands of context tokens cycling through systemctl, ulimit, iptables, unshare, and runc errors—only to fail or fall back to rewriting Dockerfiles by hand. With gvx (rungvx), the agent executes one deterministic 3-step bootstrap in a single turn and immediately runs standard docker build, docker run, and docker compose commands unchanged.

Why gvx Is Safe by Design (Not a Privilege-Escalation Workaround): Unlike mounting the host /var/run/docker.sock or running docker run --privileged (which grant root-equivalent control over the host kernel), gvx does not bypass or weaken any host security policy (PR_SET_NO_NEW_PRIVS, seccomp, AppArmor, or non-root UID limits). Instead, rungvx locks down its own host process (Landlock + PR_SET_NO_NEW_PRIVS + strict BPF seccomp allowlist) and runs dockerd inside Google's memory-safe gVisor (Sentry) user-space kernel. All guest UID 0 capabilities, overlayfs mounts (ext4lite), and iptables rules remain strictly isolated inside the sandbox process.

 1# 1. Install rungvx in user space (prebuilt SLSA-attested release or go install)
 2# Option A: Download, verify, and extract the SLSA-attested prebuilt binary from GitHub Releases
 3VERSION=$(curl -fsSL https://api.github.com/repos/gfire-sigs/gvx/releases/latest | sed -n 's/.*"tag_name": "\([^"]*\)".*/\1/p')
 4TARGET=linux-amd64 # or linux-arm64, linux-arm64v8.2
 5ARCHIVE="rungvx-${VERSION}-${TARGET}.tar.gz"
 6BASE="https://github.com/gfire-sigs/gvx/releases/download/${VERSION}"
 7
 8curl -fsSLO "${BASE}/${ARCHIVE}" "${BASE}/SHA256SUMS" "${BASE}/rungvx-${VERSION}.sigstore.json"
 9grep " ${ARCHIVE}\$" SHA256SUMS | sha256sum -c -
10gh attestation verify "${ARCHIVE}" \
11  --bundle "rungvx-${VERSION}.sigstore.json" \
12  --repo gfire-sigs/gvx \
13  --signer-workflow gfire-sigs/gvx/.github/workflows/release.yml \
14  --source-ref "refs/tags/${VERSION}" --deny-self-hosted-runners
15tar -xzf "${ARCHIVE}" && install -m 0755 "rungvx-${VERSION}-${TARGET}/rungvx" ~/.local/bin/rungvx
16
17# Option B: Or install directly from source with Go 1.27.4+
18CGO_ENABLED=0 GOBIN=~/.local/bin go install z.gfire.dev/gvx/cmd/rungvx@latest
19
20# 2. Start docker:dind inside gvx with a single-file ext4lite volume
21#    Forwards ~/.gvx/docker.sock (mode 0600) to guest port 2375 and
22#    dynamically publishes container ports on 127.0.0.1 (--auto-publish)
23mkdir -p ~/.gvx
24~/.local/bin/rungvx run \
25  --auto-publish \
26  -p unix:~/.gvx/docker.sock:2375 \
27  -v gvx-docker:/var/lib/docker \
28  -e DOCKER_TLS_CERTDIR= \
29  docker:dind --tls=false &
30
31# 3. Point the standard Docker CLI and Docker Compose at the user-space socket
32export DOCKER_HOST="unix://$HOME/.gvx/docker.sock"
33until docker info >/dev/null 2>&1; do sleep 0.5; done
34docker info --format '{{.Driver}} {{.OperatingSystem}}'
35# Output: overlayfs Alpine Linux ... (containerized)
36
37docker build -t app:test .
38docker run --rm app:test
39docker compose up -d

Why Standard Rootless Tools Fail in Restricted Sandboxes

When an engineer or autonomous coding agent needs to run docker build, docker run, or docker compose inside a hardened container or multi-tenant runner, standard workarounds fail at five distinct kernel barriers.

1. No Host Docker Daemon Socket (systemctl and service docker start Also Fail)

Running docker ps or docker build fails immediately when the host /var/run/docker.sock is not mounted into the environment, and attempting to start docker.io via systemctl or service docker start fails because PID 1 is not systemd and /etc/init.d/docker hits the container's hard ulimit -n ceiling:

1Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
2ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
3System has not been booted with systemd as init system (PID 1). Can't operate.
4Failed to connect to bus: Host is down
5/etc/init.d/docker: 62: ulimit: error setting limit (Operation not permitted)

2. PR_SET_NO_NEW_PRIVS Blocks sudo and Setuid Helpers

Hardened containers (securityContext.allowPrivilegeEscalation: false in Kubernetes, --security-opt=no-new-privileges in Docker, or exebox / bwrap sandboxes) set the Linux PR_SET_NO_NEW_PRIVS bit on the process tree. Attempting to escalate via sudo or setuid binaries (newuidmap, newgidmap, fusermount3) fails:

1sudo: The "no new privileges" flag is set, which prevents sudo from running as root.
2sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges?

3. Seccomp and Sysctl Policies Block unshare(CLONE_NEWUSER)

Tools marketed as "rootless" (Rootless Docker, Podman, Buildah, nerdctl, bubblewrap) still rely on Linux user namespaces (CLONE_NEWUSER). They fail whenever:

  • The outer container's default seccomp profile blocks unshare(2) or clone(CLONE_NEWUSER).
  • Ubuntu 24.04+ enables kernel.apparmor_restrict_unprivileged_userns = 1.
  • Debian or RHEL nodes set kernel.unprivileged_userns_clone = 0 or user.max_user_namespaces = 0.
  • newuidmap cannot write /proc/self/uid_map because PR_SET_NO_NEW_PRIVS is active.

The resulting errors look like this:

1unshare: unshare failed: Operation not permitted
2cannot clone: Operation not permitted
3Error: cannot re-exec process to join the existing user namespace
4newuidmap: write to uid_map failed: Operation not permitted
5RootlessKit: parent: failed to start the child: fork/exec /proc/self/exe: operation not permitted

4. mount(2) and pivot_root(2) Are Blocked During docker build Without Host CAP_SYS_ADMIN

Even if an environment permits CLONE_NEWUSER or dockerd is forced to start with --iptables=false --bridge=none --storage-driver=vfs, running docker build fails at the first RUN instruction because mounting a fresh /proc or calling pivot_root(2) inside a nested mount namespace is blocked:

1ERROR: failed to solve: process "/bin/sh -c ..." did not complete successfully:
2mount("/proc", "/proc", "proc", MS_NOSUID|MS_NODEV|MS_NOEXEC, NULL): Operation not permitted
3OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "proc" to rootfs at "/proc": mount proc:/proc (via /proc/self/fd/6), flags: 0xe: operation not permitted
4OCI runtime create failed: runc create failed: unable to start container process: error during container init: error jailing process inside rootfs: pivot_root .: invalid argument
5bwrap: Creating new namespace failed: Operation not permitted

5. Missing /dev/fuse Breaks fuse-overlayfs

Rootless container engines that cannot mount kernel overlayfs fall back to fuse-overlayfs. In minimal containers or Kubernetes pods without /dev/fuse device passthrough, fuse-overlayfs fails immediately:

1fuse: device not found, try 'modprobe fuse' first
2fusermount3: failed to open /dev/fuse: No such file or directory
3error initializing graphdriver: driver not supported: fuse-overlayfs

How gvx Runs docker:dind Completely in User Space

gvx bypasses all five kernel barriers because it does not ask the host Linux kernel to create namespaces, mount filesystems, or configure network interfaces. Instead, rungvx runs an internal user-space Linux kernel (the gVisor Sentry) and a user-space network stack (netstack) inside one ordinary unprivileged process.

Running Unprivileged Docker-in-Docker with gvx

1. In-Memory Namespaces and Mount Table (VFS2)

When dockerd, containerd, and runc execute inside rungvx, systrap intercepts their system calls and routes them to the in-process Sentry kernel rather than the host kernel:

  • unshare(2), clone(2), pivot_root(2), chroot(2), and mount(2) operate on the Sentry's in-memory task hierarchy and VFS2 mount table (procfs, sysfs, tmpfs, devpts, cgroupfs v2) while the host rungvx process runs under your unprivileged host UID.

2. Native overlayfs on Single-File ext4lite Volumes

When you pass -v gvx-docker:/var/lib/docker (or --mount type=volume,src=/disk/gvx-docker.ext4,dst=/var/lib/docker,size=20g), gvx mounts its built-in ext4lite filesystem at /var/lib/docker.

Because ext4lite implements a JBD2-journaled ext4 filesystem inside a single host file (gvx-docker.ext4) with support for trusted.overlay.* extended attributes, character whiteout devices (0:0), d_type, RENAME_EXCHANGE, and online hole punching (FITRIM), dockerd uses its native overlayfs storage driver inside the guest. Multi-stage docker build operations share Copy-on-Write layers without /dev/fuse and without the disk-space explosion of Docker's vfs fallback driver. You can reclaim unused space or wipe engine state at any time with rungvx volume compact gvx-docker or rungvx volume rm gvx-docker.

3. User-Space docker0 Bridge, iptables-legacy, and --auto-publish

When docker:dind starts inside gvx:

  • Guest dockerd creates the docker0 bridge (172.17.0.1/16), attaches virtual veth pairs for nested containers, and programs NAT (DOCKER, POSTROUTING) and FILTER chains with addrtype and conntrack matches inside gvx's user-space netstack.
  • Passing -p unix:~/.gvx/docker.sock:2375 binds an owner-only host Unix domain socket (mode 0600) and forwards connections directly to port 2375 of dockerd inside the sandbox.
  • Passing --auto-publish dynamically binds each docker run -p and docker compose port onto host 127.0.0.1:<port> under host lockdown (keeping port 2375 private). If you prefer zero post-boot loopback binds, omit --auto-publish and pre-declare static port ranges such as -p 127.0.0.1:9000-9019:9000-9019. Behind a corporate TLS-inspecting proxy, add --host-ca-certs so dockerd trusts host root CAs.

Comparison with Existing Container Tools

Capability / ConstraintStandard Docker (dockerd)Rootless Docker / PodmanKaniko / Buildah (Unprivileged)gvx (rungvx + docker:dind)
Host root or sudo requiredYesNoNoNo
Works with PR_SET_NO_NEW_PRIVS=1NoNo (newuidmap fails)PartialYes
Works when unshare(CLONE_NEWUSER) is blocked (EPERM)N/ANoBuildah: No / Kaniko: YesYes
Works without /dev/fuseYes (uses kernel overlay2)Only via slow vfs copyYesYes (overlayfs on ext4lite)
Supports docker build (BuildKit)YesYes (if userns allowed)Image build only (no runtime)Yes
Supports docker run and docker compose upYesYes (if userns allowed)NoYes
Runs on Windows and macOS without a Linux VMNo (requires WSL2 / VM)No (requires Linux VM)NoYes (whpx, hvf, systrap)

Exact Host Kernel Requirements on Linux

gvx requires zero elevated capabilities (CapEff: 0000000000000000) and zero user namespaces, and supports both 4 KiB and 16 KiB host pages on linux/amd64 and linux/arm64. On a Linux host, rungvx relies on only three standard unprivileged kernel primitives:

  1. ptrace(PTRACE_ATTACH) on its own child thread once during initialization: systrap spawns a local stub helper thread at startup, attaches to it to initialize the shared-memory context, and detaches. If the host sets kernel.yama.ptrace_scope = 3 (which disables all ptrace system-wide) or blocks ptrace in an outer seccomp filter, systrap initialization cannot complete. (Under yama.ptrace_scope = 1, the default on Ubuntu and Debian, gvx succeeds because parent-to-child tracing is permitted.)
  2. seccomp(SECCOMP_SET_MODE_FILTER): Used to trap guest system calls from container stub threads. As covered in Part 3 of this series, gvx works both when SECCOMP_FILTER_FLAG_NEW_LISTENER is available and when it returns EBUSY inside a nested sandbox.
  3. mmap(..., PROT_EXEC, ...): Used to map guest ELF segments and the systrap shared-memory trampoline.

End-to-End Example: Building and Testing a Multi-Container App Without Root

The following script runs a complete docker build and two-container integration test (redis + application container) inside an unprivileged user session:

 1mkdir -p ~/.gvx
 2rungvx run \
 3  --auto-publish \
 4  -p unix:~/.gvx/docker.sock:2375 \
 5  -v gvx-docker:/var/lib/docker \
 6  -e DOCKER_TLS_CERTDIR= \
 7  docker:dind --tls=false &
 8DIND_PID=$!
 9
10export DOCKER_HOST="unix://$HOME/.gvx/docker.sock"
11until docker info >/dev/null 2>&1; do sleep 0.5; done
12
13mkdir -p /tmp/demo-app && cd /tmp/demo-app
14cat <<'EOF' > Dockerfile
15FROM alpine:3.20
16RUN apk add --no-cache redis
17CMD ["redis-cli", "-h", "cache", "ping"]
18EOF
19
20# Build the image using overlayfs on ext4lite
21docker build -t demo-ping:latest .
22
23# Create a bridge network, start Redis, and verify connectivity between containers
24docker network create demo-net
25docker run -d --name cache --network demo-net redis:7-alpine
26docker run --rm --network demo-net demo-ping:latest
27# Output: PONG
28
29# Clean up workload containers and stop the sandbox
30docker rm -f cache
31docker network rm demo-net
32kill -INT $DIND_PID

Further Reading in This Series

  1. gvx: Running Linux Containers, Docker, and Kubernetes in One Unprivileged Process: Architectural overview of gvx, its cross-platform execution engines (whpx, hvf, systrap), VFS2 (erofs, ext4lite, hostfs, rpcfs), and netstack.
  2. Running Docker, docker build, and docker compose Without Root or User Namespaces (this post)
  3. Running Docker-in-Docker Inside gVisor and Nested Sandboxes with gvx: How gvx solves modprobe, iptables-nft, overlay2 on gofer, and nested SECCOMP_FILTER_FLAG_NEW_LISTENER (EBUSY) inside gVisor (runsc).
  4. Fast Isolated Docker Environments for AI Agent RL Rollouts with gvx: Scaling parallel SWE-bench and RL rollout environments with 100-millisecond copy-on-write .ext4 volume resets.