Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Docker 13 min read How-to mediumAdept

Docker Best Practices: Choosing Between RUN, CMD, and ENTRYPOINT

RUN executes commands at image build time and creates layers, CMD sets a default command that any docker run arguments replace, and ENTRYPOINT fixes the executable so that run arguments are appended to it. Pairing an exec-form ENTRYPOINT with CMD as default arguments gives a container that acts like a standalone executable whose parameters users can override. Exec form is preferred for CMD and ENTRYPOINT because the process runs directly as PID 1 and receives signals such as SIGTERM, which allows graceful shutdown. Shell form runs under /bin/sh -c, which usually does not forward signals, so it fits only cases that need pipes, globbing or variable expansion. An ApacheBench example shows a URL argument overriding CMD and failing as a command.

Assumes: Dockerfile basicsUnix processes and signals

Related posts

  • Docker Best Practices: Using ARG and ENV in Your Dockerfiles

    Docker mediumAdept

    ARG defines variables available only during the image build, while ENV defines variables available at build time and at container runtime. Worked examples show ARG values overridden with --build-arg or Compose build args. ENV cannot be declared without a value, so runtime values come from docker run -e, --env-file, or Compose environment interpolation via the shell, an inline variable, or a .env file. Rule of thumb: use ARG for build-only values and ENV for anything needed at runtime.

  • Docker Best Practices: Understanding the Differences Between ADD and COPY Instructions in Dockerfiles

    Docker mediumAdept

    Dockerfile COPY only copies files and directories from the build context into an image layer. ADD can do the same, but it also downloads URLs and automatically extracts local and remote archives. That extra behaviour brings flexibility, but also unpredictability and security risk from external content, so COPY is the sensible default and ADD should be reserved for cases that need fetching or extraction. Both instructions also work with remote build contexts such as Git repositories, remote tarball URLs and OCI images, with COPY still scoped to the context.

  • Introducing Docker Build Checks: Optimize Dockerfiles with Best Practices

    Docker mediumAdept

    Docker Desktop 4.33 adds Build checks, which evaluate Dockerfiles against codified best-practice rules during `docker build` and report warnings. Because the checks are part of the build itself, they also consider build arguments and base images rather than only linting the text. `docker build --check` runs the evaluation in under a second without executing the build, and `# check=error=true` makes warnings fail CI. Individual rules can be disabled with `# check=skip=...`, and the checks also work with multi-stage builds, Bake and Docker Build Cloud.

  • Docker Best Practices: Using Tags and Labels to Manage Docker Image Sprawl

    Docker mediumAdept

    Docker's `latest` tag does not mean the newest version: it is simply applied to the most recent build or push made without an explicit tag, and mutable tags like `v1.0.0` can be silently overwritten or mis-applied. A worked example shows `latest` pointing to 1.0.0 after 1.0.1 ships, and a `1.0.1` tag actually running 1.0.2 code. The recommended fix is embedding version metadata with the `LABEL` instruction, which can be checked via `docker inspect` without running the container. It also suggests using the OCI `org.opencontainers.image.*` label set and namespaced custom labels for team-specific metadata.

  • Coding Agent Horror Stories: The Command You Already Approved

    Docker mediumAdept

    CVE-2026-22708 in Cursor let shell built-ins like `export`, `typeset` and `declare` run outside the Auto-Run allowlist, so injected text could silently set variables such as `PAGER`, `PYTHONWARNINGS` or `PERL5OPT` and turn an approved command like `git branch` into arbitrary code execution, even with an empty allowlist. The chain in Pillar Security's research ended with SSH private keys being exfiltrated. Running the agent inside Docker Sandboxes microVMs does not stop the injection, but it keeps the key file out of reach, discards `~/.zshrc` persistence and limits egress through deny-by-default network policy. Caveats remain: the live host workspace (Git hooks, Makefiles), the shared skills store, and a forwarded SSH agent socket, which declarative kits and org-level governance with SIEM audit logs are meant to constrain.

The quest for software engineering knowledge.

Look:
Layout: