perf(docker): socket-activate dockerd instead of starting it at boot - #430
Open
runleveldev wants to merge 1 commit into
Open
perf(docker): socket-activate dockerd instead of starting it at boot#430runleveldev wants to merge 1 commit into
runleveldev wants to merge 1 commit into
Conversation
Enable only docker.socket, not docker.service, so dockerd (and its containerd dependency) start lazily on first use of /run/docker.sock rather than eagerly at container boot. Containers that never touch Docker no longer pay for an idle dockerd + containerd. The stock docker.service already ships the canonical socket-activation setup (ExecStart uses `-H fd://` and it declares Requires=docker.socket), so enabling the socket alone is sufficient: the first client connection starts the service on demand. containerd has no socket unit and cannot be socket-activated itself, but docker.service pulls it in (Wants/After=containerd.service), so it too stays stopped until Docker is first used. Verified: with only docker.socket enabled, `systemctl is-active docker.service` reports inactive at boot; `docker info` (first socket connection) transparently starts dockerd, which in turn brings up containerd; both then report active.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the images/docker base image to rely on systemd socket activation for Docker, aiming to avoid starting dockerd (and containerd) eagerly at boot in downstream containers that never use Docker.
Changes:
- Enable only
docker.socket(instead of enabling bothdocker.serviceanddocker.socket) to support lazy daemon startup. - Add detailed inline documentation explaining why socket activation is expected to work with stock Docker CE unit files.
| docker-buildx-plugin \ | ||
| docker-compose-plugin && \ | ||
| systemctl enable docker.service docker.socket && \ | ||
| systemctl enable docker.socket && \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The docker image currently runs
systemctl enable docker.service docker.socket, which starts dockerd eagerly at boot (plus itscontainerddependency) in every container built ondocker/docker-nodejs— whether or not that container ever uses Docker.This changes it to enable only
docker.socket, so dockerd and containerd start lazily on first use of/run/docker.sock. Containers that never touch Docker (e.g. web-IDE / studio workloads) no longer carry an idle dockerd + containerd.Why this is safe / needs no unit edits
The stock
docker.servicefrom Docker's APT package already ships the canonical systemd socket-activation setup:ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock(binds the inherited socket fd)Requires=docker.socketWants=containerd.service/After=... containerd.serviceSo enabling the socket alone is sufficient — the first client connection starts the service on demand, and
docker.servicein turn pulls upcontainerd.containerd note: containerd ships no
.socketunit and cannot be socket-activated on its own (it creates and listens on its own gRPC socket at startup). It doesn't need to be: as a dependency ofdocker.serviceit stays stopped until Docker is first used.Verification
Simulated the change in a running container built from this image (disabled
docker.service, left onlydocker.socketactive):dockerd started transparently on the first socket connection and brought containerd up with it.
Impact
dockerCLI work identically; the daemon just starts on demand.dockergroup access (pam_group) is unaffected — the socket unit and docker group are untouched.ozwell-studio, which builds ondocker-nodejs) inherit the lazy-start behavior automatically, trimming idle memory/CPU.