docker

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package docker is the fallback backend for Linux hosts without KVM. Each sandbox is a container of the base guest image on a rootful Docker Engine, reached through the Engine API on its unix socket (DOCKER_HOST if that is a unix:// URL, else /var/run/docker.sock). The client is plain net/http and negotiates API version 1.41 (Docker 20.10) to 1.47.

Containers share the host's kernel, so isolation is weaker than a Firecracker microVM: a kernel exploit escapes. Container root is the host's uid 0 unless the engine remaps user namespaces. Warning says so: doctor prints it, the daemon logs it at start and serves it in /v1/info, for the commands that will create sandboxes (#15) to print.

This is not Docker Sandboxes (https://docs.docker.com/ai/sandboxes/), which runs each sandbox in a microVM and needs KVM locally (https://docs.docker.com/ai/sandboxes/install/), so it cannot stand in on hosts without it.

Resources

Sandbox ID x in state directory S has a container, a bridge network and a volume, all called boxpool-<hash of S/docker>-x and labelled run.boxpool.owner=S/docker and run.boxpool.sandbox=x, and the directory S/docker/x (0700) with agent/ (0777) in it. The driver lists only containers with its owner label, and before starting, stopping or removing anything checks the name and both labels: a name prefix is not proof of ownership. It removes nothing in New, so running sandboxes survive a daemon restart and a new Driver uses them as they are.

Hardening

  • All capabilities dropped and none added; no-new-privileges; Docker's default seccomp and AppArmor profiles; not privileged; no host PID, IPC or network namespace; no devices; no published ports.
  • A read-only root filesystem. /root, the volume, is HOME, the working directory and the only path that persists across Stop and Start; it starts as the image's /root. /tmp and /var/tmp (each half the memory limit) and /run (16 MiB) are tmpfs, emptied by Stop. Installing system packages fails; that needs a writable root, which this backend does not offer.
  • Spec.CPUs and Spec.MemoryMB become CPU and memory limits, with no swap; at most 4096 processes. A cpuset also makes nproc report Spec.CPUs. Spec.DiskGB is advisory: a plain named volume has no portable quota, so Docker disk growth is not limited or reserved. Monitor the Engine's data filesystem. /proc/meminfo and free report host memory; inspect the memory cgroup for the enforced limit.
  • Each sandbox has its own bridge network, and Docker's own rules drop traffic between bridges, so sandboxes cannot reach each other. The engine manages the bridges; boxpool adds host nftables isolation.

The only host path in the container is the sandbox's agent directory, on /run/boxpool. No Docker socket, /dev/kvm, home or other sandbox is mounted. The image's agent listens on agent.sock there as root without capabilities, so it cannot write the daemon's 0700 directory or chown its socket; the container's command makes the socket 0666 and the 0777 agent directory lets it create it. The 0700 sandbox directory keeps every other host user out.

The guest owns everything in the agent directory, so the daemon never follows what is there: Dial opens agent.sock with O_PATH|O_NOFOLLOW, refuses anything but a socket (a symlink to another sandbox's socket, say) and connects through /proc/self/fd to the inode it opened, so a later swap cannot redirect it. That needs /proc on the host.

Limits

  • Linux hosts only, rootful Docker only. Rootless Docker, Podman and gVisor are out of scope; Docker Desktop's VM cannot connect a bind-mounted unix socket to the host.
  • A root daemon, ip and nft are required. Per-network nftables tables deny host services before DNAT, IPv6, spoofing and forwarding except through the outbound interface; replies to host-initiated flows work. New restores rules before adoption; Start restores them even for running containers. Failed restoration stops owned running containers. Remove keeps rules until network deletion succeeds. Docker embedded DNS remains an infrastructure exception. See docs/security.md for lifecycle limits.
  • Each sandbox's network takes a subnet from the engine's address pools, about 30 by default; raise default-address-pools in daemon.json for more.
  • SELinux hosts would need the agent directory relabelled; not handled.
  • Pause and Resume are not supported; the daemon stops and starts the sandbox instead, losing its memory.
  • Snapshot saves only /root, as a tar from the Engine's archive API, and Create with Spec.From extracts it there. The root file system is read-only, so docker commit would save nothing the guest changed.

Shared resource admission (internal/resources) keeps one CPU and the larger of 1 GiB or 10% of memory for the host. Defaults are 2 CPUs, 2048 MiB and 10 GiB. S/docker/x/resources.json retains the reservation until Remove, including after Stop or a failed Create whose rollback could not finish. New records the limits of older verified containers without changing their settings; old containers keep their old affinity.

Index

Constants

View Source
const DefaultDesktopImage = "ghcr.io/sukhendu2002/boxpool-desktop@sha256:25256b5eec5c09adea93d145be01b393a7b73359084346deedd14e441bea9aba"

DefaultDesktopImage pins the matching two-architecture desktop index.

View Source
const DefaultHost = "/var/run/docker.sock"

DefaultHost is the Engine API socket used when DOCKER_HOST is unset.

View Source
const DefaultImage = "ghcr.io/sukhendu2002/boxpool-image@sha256:5fe9553b95799a5af4427279ea45cf9666dcb3e7db0ebbd66aa2088bde454734"

DefaultImage is the base guest image release v0.1.2-image.3, pinned by the digest of its two-architecture index, the same release as the Firecracker artifacts.

View Source
const Warning = "" /* 126-byte string literal not displayed */

Warning is what every entry point that picks or creates Docker sandboxes shows: the fallback is weaker than the microVM backends.

Variables

This section is empty.

Functions

func Probe

func Probe(ctx context.Context) (string, error)

Probe reports the Docker Engine's version, or why it cannot be used.

Types

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver is the Docker backend. All its state is in the engine and the sandbox directories, so a new Driver sees, and can use, the sandboxes an earlier one created, including running ones.

func New

func New(ctx context.Context, stateDir string) (*Driver, error)

New connects to the Docker Engine (DOCKER_HOST if it is a unix:// URL, else /var/run/docker.sock) and creates the docker directory in stateDir. It changes nothing in the engine.

func (*Driver) Create

func (d *Driver) Create(ctx context.Context, id string, spec backend.Spec) (_ backend.Sandbox, err error)

Create makes the sandbox's directory, volume, network and container, pulling the image if the engine lacks it. Spec.Image, if set, must pin a tag or digest; the default is DefaultImage. With Spec.From, /root starts as the snapshot's instead of the image's. On failure it removes what it made, and never touches resources that already existed.

func (*Driver) Dial

func (d *Driver) Dial(ctx context.Context, id string) (net.Conn, error)

Dial connects to the agent in a running sandbox, for agent.NewClient.

func (*Driver) List

func (d *Driver) List(ctx context.Context) ([]backend.Sandbox, error)

List returns the driver's sandboxes, running or not, found by their labels.

func (*Driver) Logs

func (d *Driver) Logs(ctx context.Context, id string, follow bool) (io.ReadCloser, error)

func (*Driver) Name

func (d *Driver) Name() string

func (*Driver) Pause

func (d *Driver) Pause(ctx context.Context, id string) error

Pause and Resume are not supported: Docker cannot save a container's memory. The daemon stops and starts the sandbox instead.

func (*Driver) Remove

func (d *Driver) Remove(ctx context.Context, id string) error

Remove deletes the sandbox's container, network, volume and directory, killing the container if it runs. Each step skips what is already gone, so Remove can be repeated after a failure; a resource with the sandbox's name that the driver does not own is an error and is kept.

func (*Driver) Resume

func (d *Driver) Resume(ctx context.Context, id string) error

func (*Driver) Snapshot

func (d *Driver) Snapshot(ctx context.Context, id, path string) (err error)

Snapshot saves /root of a stopped sandbox, the only path that persists, to path as a tar of its contents. The root file system is read-only, so docker commit would save nothing the guest changed. A running sandbox is refused: its files may be mid-write.

func (*Driver) Start

func (d *Driver) Start(ctx context.Context, id string) error

Start starts the container and returns once its agent answers. Starting a running sandbox does nothing. If the start request fails or the agent does not answer, the container is stopped again: a failed request may still have started it, if only the answer was lost.

func (*Driver) Stop

func (d *Driver) Stop(ctx context.Context, id string) error

Stop stops the container: SIGTERM, then SIGKILL after stopTimeout. Files under /root stay; the tmpfs mounts are emptied. Stopping a stopped sandbox does nothing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL