Podcast about DevSecOps

#45 - What is happening with Docker?

BuildKit secrets and remote caching address build problems that Docker teams may still be working around.

18 min read

Have you heard any recent news from Docker? We haven’t. That is why we decided to check up on Docker to see how it is doing and go through the tool’s history and adoption. Clueless about the difference between Docker, Containerd, CRI-O? We got you covered. Also, we will highlight a couple of new handy capabilities added recently.

Discuss the episode or ask us anything on LinkedIn


Docker went quiet, and the quiet cost you something

When did you last read a Docker release note? For most of us the honest answer is somewhere around 2016. The CLI kept the same verbs, the Dockerfile kept the same instructions, and nothing in the day job forced anyone to check what changed. So several years of features sit unused in a tool you run fifty times a day. Two of them are worth switching on this week. If your build copies a private-repository key into an image layer, deleting it later won’t remove it from that layer. And your CI job rebuilds every layer each run, because the runner starts empty.

The silence has a business reason behind it. Docker Inc. spent years trying to sell products on top of software it was giving away, and open source alternatives kept arriving faster than the company could ship. In November 2019 it sold the enterprise platform business, Docker Trusted Registry and Universal Control Plane included, to Mirantis, and refocused on developer tooling. Container news moved to Kubernetes, to the CNCF projects and to the registry vendors.

Meanwhile the thing under your CLI was taken apart. “Docker” now names a company, a daemon, a client, a file format and a set of components other people’s tools are built from. Kubernetes removed its Docker-specific shim in version 1.24 in May. Knowing which piece is which is what tells you where to look when a build leaks a token or a node stops starting containers.

Your build arguments can end up in the image

Start with the feature that pays for the rest of this page.

Why shouldn’t you pass a token with --build-arg?

Because the value can leak: build arguments and their values can be recorded in the image’s metadata and build history, and anyone who pulls the image can read them back.

Docker’s own documentation on build variables says not to use ARG for secrets, because values passed that way may end up visible to any user of the image through docker history and the image metadata. ENV is worse, since it persists into the image configuration for every process that runs in the container. Deleting the file in a later RUN doesn’t save you either, because the layer that created it is still in the image.

BuildKit replaced both habits. docker build --secret id=npmrc,src=$HOME/.npmrc hands the file to one instruction, RUN --mount=type=secret,id=npmrc, which mounts it under /run/secrets for the length of that step and takes it away afterwards, so the file is not committed to a layer (build secrets docs). The mount is the part you get for free, and it’s the only part. If the command you run copies the value into a file it leaves behind, writes it into a lockfile or prints it into the build log, that copy persists, so check what the consuming command does with what you handed it. SSH works the same way with one difference: docker build --ssh default forwards the agent socket rather than the key itself, so only a step marked RUN --mount=type=ssh can reach it, and what that step gets is the ability to authenticate as you while it runs. That’s what makes a build that pulls private Go modules from GitHub work without a deploy key ending up in the image.

One catch, plus a note on versions. These need BuildKit, which on an older engine means DOCKER_BUILDKIT=1 in the environment. Newer Dockerfile features also need a frontend newer than the one built into your engine, selected on the first line of the file with # syntax=docker/dockerfile:1. That tag follows the latest stable 1.x release, and docker/dockerfile:1.4 follows the latest 1.4.x, so neither one pins anything. When you want every build to use the same frontend, name the full patch release: # syntax=docker/dockerfile:1.4.3. Docker’s stable channel documentation calls those full-version tags immutable. The image digest is the other way to pin it.

An hour of CI you don’t have to spend

The same build engine fixes the other weekly annoyance, which is paying again for work you already did.

How do you get a layer cache on a runner that starts empty?

Point the build at a registry. BuildKit compares layer hashes against what’s already there and pulls the layers it can instead of rebuilding them.

We have an R image, the data science language, whose dependencies take an hour to build. On a hosted runner there’s no cache from the previous build, so every pipeline run paid that hour again, including the runs where nothing in the image had changed. With a registry as the cache backend, those layers get downloaded and only the changed ones get rebuilt.

Which form you can use depends on the builder, and the --cache-to flag belongs to Buildx rather than to docker build. The default docker driver exports inline cache only, and the whole command is docker buildx build --cache-to type=inline --push -t myorg/app ., read back on the next run with docker buildx build --cache-from myorg/app -t myorg/app --push . (Docker, March 2022). On a BuildKit-enabled docker build, a build argument does the same job: docker build -t myorg/app --build-arg BUILDKIT_INLINE_CACHE=1 ., then docker push myorg/app, and docker build --cache-from myorg/app . wherever you build next (docker build reference, 20.10.21). A separate cache reference, --cache-to type=registry,ref=myorg/app:buildcache, needs docker buildx build on a docker-container builder, created once with docker buildx create --driver docker-container --use (buildx v0.9.1 reference). Inline is less setup; the registry form keeps the cache out of the image and can hold layers from stages you never ship (cache backends documentation).

It isn’t free. You trade CPU time for network time, and a cache nobody pushes is a cache nobody hits. An hour of waiting per pipeline run is still the kind of waste that pays back the setup in a week.

The Dockerfile learned things while you weren’t looking

Build secrets are the headline. The file itself has picked up a few things too, starting with the one we keep recommending to everybody.

Why is your compiler still in the image you ship?

It doesn’t have to be. A multi-stage build compiles in one stage and copies the result into a clean one, so the toolchain never reaches the image that runs in production.

Two FROM instructions in the same file. The first carries the SDK and your source, the second starts from something small, scratch for a static Go binary, and takes only what it needs: COPY --from=build /out/app /app. The compiler, the module cache and your source stay behind in the first stage, out of the image you ship (multi-stage builds). Images get smaller, and a runtime image with no shell and no package manager is a worse place for an attacker to land.

That guarantee covers the runtime image and stops there. The registry cache from the previous section keeps the layers of intermediate stages when you export it with mode=max (BuildKit’s export cache notes), so your source, and any credential you brought in with COPY instead of --secret, rides along in the cache you push.

When the second stage misbehaves, build the first on its own: docker build --target build -t app:build . stops after that stage and tags it, then docker run --rm -it app:build sh puts you inside to see what the compile produced. --target picks the stage to build and does nothing else (stop at a specific build stage): no shell, no skipping past an instruction that fails, so the stage has to build cleanly first.

Three smaller changes affect the file itself. Heredocs moved from the labs channel to stable in Dockerfile 1.4, so on a 1.4 frontend you write RUN <<EOF, your script, EOF, instead of escaping newlines. The same notation writes a file inline, COPY <<EOF /etc/config (introduction to heredocs in Dockerfiles, July 2021). That’s the end of trailing backslashes, but not of the reason for the &&: a chain stops at the first command that fails, and the lines of a heredoc keep running unless you say otherwise. Open the script with set -eu, or keep the &&.

Then there’s --chown, which isn’t new at all and still surprises people. COPY --chown=app:app . /app sets ownership as the files land, instead of copying as root and fixing it afterwards in a RUN chown that duplicates the data in a second layer.

HEALTHCHECK has been a Dockerfile instruction since 1.12, in July 2016, and we don’t reach for it, because whatever orchestrates your containers already owns that question.

The docker command doesn’t run anything

Those are the things to use this week. The rest of this is about what the word Docker refers to now, because the answer decides which piece you go and look at when something breaks.

What happens when you type docker run?

The CLI sends an HTTP request to a daemon. The daemon hands container work to containerd, containerd starts a shim, and the shim runs runc, which asks the kernel for the cgroups and namespaces.

Not every command goes that far down. docker ps stops at the first hop: the daemon answers from the container state it already keeps, and no shim or runc is involved. What the two have in common is the part people miss, that the thing you type is a client and the work happens somewhere else.

Docker got from 0.1.0 in March 2013 to 1.0.0 with production support in June 2014, then spent the next two years taking itself apart. From 1.11 in April 2016 a Linux install is four binaries rather than one: docker, docker-containerd, a docker-containerd-shim per container and docker-runc (changelog). That first binary was still both halves at the time, the client you type and the engine you started with docker daemon; the daemon moved into its own dockerd binary in 1.12, three months later. containerd supervises containers and manages images. runc is the small piece that actually starts your process and exits.

The daemon doesn’t have to be on your machine, and that’s where this bites. People exposed the Docker socket to the internet and found strangers starting containers on their hosts, which is also how Unit 42’s Graboid worm spread cryptominers in 2019. If you’ve ever bound the daemon to a TCP port for convenience, read protect the Docker daemon socket before you leave it.

Two standards, one for the image and one for the run

Those internal boundaries matter because somebody wrote them down.

What do the two container standards actually cover?

The Open Container Initiative image specification covers the thing you push, filesystem layers plus a config, and the runtime specification covers how a bundle of that gets executed. Both reached 1.0 in July 2017.

The obvious joke about standards is the xkcd one, fourteen competing standards and a fifteenth written to unify them, and this time it went better than that. The runtime spec is why containerd can call something other than runc. Google’s gVisor puts a user-space kernel between your application and the host and ships runsc as an OCI runtime. Kata Containers backs containers with a virtual machine instead of the host kernel, and on Kubernetes the usual unit is a VM per pod with the pod’s containers inside it (Kata architecture). AWS’s Firecracker isn’t an OCI runtime at all, it’s a virtual machine monitor on KVM built for serverless workloads, and reaching it from containerd takes firecracker-containerd in between.

What that isolation costs depends on the runtime and the workload, system-call overhead in one place, slower start-up in another. gVisor’s performance guide puts its own overhead in system calls and file operations, and says CPU-bound work runs natively. Its compatibility page is blunt about the rest: try your workload, because unimplemented features and bugs exist.

Kubernetes needed a different boundary. Before the Container Runtime Interface, Docker and rkt were wired into the kubelet’s own source. CRI turned the runtime into a gRPC service with an image half and a container half, which containerd and CRI-O both implement natively. Docker was reached through a shim the Kubernetes project maintained, and that shim is what 1.24 removed.

If the removal still worries you, the dockershim removal FAQ settles the image half: what you build with docker build keeps working under containerd and CRI-O. BuildKit can write Docker or OCI media types and both runtimes take either (BuildKit’s image output docs), so the difference between the two formats doesn’t reach you.

What does need checking is everything else on the node that talks to /var/run/docker.sock: log collectors, monitoring and security agents, in-cluster build jobs. When the node stops running Docker Engine that socket isn’t there, and the FAQ’s advice is to go and find those dependencies before the upgrade rather than during it.

Build once, run everywhere, with the everywhere in small print

Standards made the runtimes swappable. They didn’t make the slogan on the tin true.

Does “build once, run everywhere” hold?

It holds for Linux on the architecture you built for, and gets conditional everywhere else.

This is where we disagree. Julien treats the line as 2014 marketing: the exceptions never stopped arriving, phones never happened, the old box never worked, and he’s stopped expecting a universal runtime. Andrey’s answer is that a leader points at a direction and gets everyone moving, and the industry has been moving in that direction ever since, which is worth having even unreached.

Both of us hit the same counterexamples. The Windows containers we worked with used Windows Server Core, which was around a gigabyte as a base image last time we looked, and Microsoft publishes lighter Windows bases as well, Nano Server among them (Windows container base images). An M1 MacBook runs amd64 images by emulating them, and as soon as a dependency has to be compiled, “you’re in a world of pain”; the real fix is publishing multi-platform images rather than hoping emulation holds. Size has its own ceiling: machine learning images carry model weights, we’ve seen one at 127 GB, and at that point whether this should be an image at all is a fair question.

The older limit hasn’t moved either. Containers suit applications that log to stdout and keep their state somewhere you chose. An application that writes everything to its filesystem becomes a stateful container, and then NFS turns up, EFS if you’re on AWS, and everything gets harder.

If you want off Docker, know what you’re swapping

So what are the alternatives, now that the runtime underneath is a commodity?

What do you give up by switching to Podman?

A shared view of your images, mostly. Podman and Docker keep separate image stores, so something you build with one doesn’t appear in the other’s images listing.

The two CLIs are close enough that the switch looks free, right up to the moment two tools on the same laptop disagree about what exists. Pick one per machine, learn its edges, and change only when you have a reason.

If the reason you’re shopping around is root, Docker answered that one. Rootless mode arrived as experimental in 19.03 and graduated in 20.10, which removes the objection enterprise security teams raised for years, that every developer who runs a container needs root on the machine. The rootless documentation lists what still doesn’t work there, and it’s worth reading before you promise it to anyone.

The one we’d actually try is nerdctl, a Docker-compatible CLI for containerd that tagged 1.0.0 in October 2022. Same commands, plus two things Docker doesn’t offer: lazy pulling, where a container starts before the image has finished downloading, and encrypted images. It isn’t positioned as a competitor so much as a place to try ideas that can flow back into the ecosystem everyone else uses.

A warning from the other direction. rkt, the alternative everyone cited in 2015, came to Red Hat with CoreOS in 2018 and was archived by the CNCF in August 2019 over declining adoption and unpatched CVEs. Swapping a component has a decent track record. Swapping the whole stack has a worse one.

What this means for teams

The componentization that looked at the time like Docker Inc. losing the plot is what kept this ecosystem moving. nerdctl exists because containerd is its own project. gVisor plugs in because the runtime spec is written down. Your images survived the removal of the shim that used to run them. The cost of all that is that nobody sends you the news anymore, so the features arrive and nothing tells you.

Four things worth doing this week:

  • Run docker history --no-trunc on your most recent production image and look for credentials in ARG and ENV. Without that flag the output cuts each instruction short, which is where the values would be (docker history reference). It lists build instructions and image metadata; to see a file that a COPY brought in, you have to open the layer itself. Move what you find to --secret and --ssh, and switch BuildKit on wherever it isn’t.
  • Take your slowest pipeline build, add a cache backend and compare two runs. Inline cache works on the builder you already have, through --build-arg BUILDKIT_INLINE_CACHE=1 on docker build or --cache-to type=inline on Buildx; a registry cache needs a docker-container builder. Ours went from an hour to a skip.
  • Check what your Kubernetes nodes actually run. From 1.24 the kubelet needs a CRI endpoint, which means containerd, CRI-O, or Docker Engine behind the cri-dockerd adapter, and it means auditing whatever else on those nodes used the Docker socket. Your existing images remain compatible; build jobs that depend on the node’s Docker socket need migration.
  • Pin the frontend your Dockerfiles ask for, # syntax=docker/dockerfile:1.4.3 or a digest, and move your scripts from docker-compose to docker compose, generally available since April 2022. Docker Desktop 4.4.2 and later aliases the old name to the new one for you; on a Linux install you set that alias up yourself, so run the scripts you already have against V2 before you count on them. Ours was an end-to-end test harness orchestrated by Compose, and it needed tinkering on Ubuntu 22.04. Container names also use hyphens now where V1 used underscores, which the --compatibility flag puts back.

Common questions, answered

How do I clone a private repository during docker build without leaving a key in the image?

Forward your SSH agent instead of copying a key in: build with docker build --ssh default and mark the instruction that needs it RUN --mount=type=ssh. The key stays in the agent, so no layer holds it. What crosses into the build is the ability to authenticate as you: every command in that step can use the agent while the step runs, so keep that step to the fetch you meant. The copy-back risk sits with --secret file mounts, where a command that writes one into a file it keeps puts it back in the image. It needs BuildKit, so set DOCKER_BUILDKIT=1 on an older engine. A key added with COPY and deleted in a later step is still in the layer that added it.

Do I have to rebuild my images now that Kubernetes 1.24 removed dockershim?

No. The change is about what runs containers on the node, not about what you build. Images produced by docker build keep working under containerd and CRI-O, which accept both the Docker and the OCI media types BuildKit writes, and Docker Engine itself can stay behind the cri-dockerd adapter. What does need checking is anything on your nodes that talked to the Docker socket directly, such as log collectors or in-cluster build jobs, because that socket may not be there after the node runtime changes.

How do I run Docker without giving developers root?

Use rootless mode, which stopped being experimental in Docker Engine 20.10. The daemon and the containers run as an unprivileged user inside a user namespace, which answers the objection security teams have raised since 2013. It isn’t feature-identical to the rootful daemon, so read the limitations in the rootless documentation against your own workloads before you roll it out to a team.

Resources

Since we recorded

Compose V1 reached the end of its support in June 2023 and was removed from Docker Desktop (Docker, January 2023). The componentization has since reached the default install: from Docker Engine v29 in November 2025, the containerd image store is the default for new installations and the legacy graph drivers are deprecated, which means the pieces split out in 1.11 are now what a fresh docker pull uses. nerdctl released 2.0.0 in November 2024. We returned to the whole question in episode 109, Docker Got Quiet. Did You Miss Anything?