Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
openaec-foundation avatar

Docker Syntax Dockerfile

  • 8 installs
  • 9 repo stars
  • Updated July 8, 2026
  • openaec-foundation/docker-claude-skill-package

Helps with devops & ci/cd tasks.

About

docker-syntax-dockerfile is a Claude Code skill for devops & ci/cd. It helps solo builders move faster with AI-assisted development.

  • docker-syntax-dockerfile
  • DevOps & CI/CD
  • AI-coding skill

Docker Syntax Dockerfile by the numbers

  • 8 all-time installs (skills.sh)
  • Ranked #1,044 of 1,435 DevOps & CI/CD skills by installs in the Skillselion catalog
  • Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/openaec-foundation/docker-claude-skill-package --skill docker-syntax-dockerfile

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs8
repo stars9
Last updatedJuly 8, 2026
Repositoryopenaec-foundation/docker-claude-skill-package

What it does

Helps with devops & ci/cd tasks.

Files

SKILL.mdMarkdownGitHub ↗

docker-syntax-dockerfile

Quick Reference

Parser Directives

Parser directives MUST appear at the very top of the Dockerfile, before any instructions, blank lines, or comments.

DirectivePurposeExample
# syntax=docker/dockerfile:1Enable BuildKit features (heredocs, mounts, etc.)ALWAYS include this
# escape=\`Change escape character (useful on Windows)Optional
# check=error=trueEnable build-time lint checks (v1.8.0+)Optional

ALWAYS start every Dockerfile with # syntax=docker/dockerfile:1 to enable BuildKit extensions.

All 17 Instructions at a Glance

InstructionPurposeCreates Layer?
FROMSet base image, start build stageYes (base)
RUNExecute command during buildYes
CMDDefault container command (overridable)No (metadata)
ENTRYPOINTContainer executable (persistent)No (metadata)
COPYCopy files from context or stageYes
ADDCopy with URL download and tar extractionYes
ENVSet persistent environment variableYes
ARGSet build-time variable (not persisted)No
WORKDIRSet working directoryYes
EXPOSEDocument container portNo (metadata)
VOLUMEDeclare mount pointNo (metadata)
USERSet user for subsequent instructionsNo (metadata)
HEALTHCHECKDefine container health testNo (metadata)
LABELAdd image metadataYes
SHELLOverride default shellNo (metadata)
STOPSIGNALSet container stop signalNo (metadata)
ONBUILDDeferred instruction for child imagesNo (metadata)

Critical Warnings

NEVER use latest tag in FROM -- ALWAYS pin to a specific version (node:20.11-bookworm-slim) or digest for reproducibility.

NEVER store secrets in ENV or ARG -- they are visible in docker history. ALWAYS use RUN --mount=type=secret instead.

NEVER use ADD when COPY suffices -- ADD has implicit behaviors (auto-extraction, URL download) that make builds less predictable.

NEVER use shell form for ENTRYPOINT -- the application will NOT be PID 1 and will NOT receive signals for graceful shutdown.

NEVER separate apt-get update and apt-get install into different RUN instructions -- the update layer gets cached and becomes stale.

ALWAYS combine related RUN commands with && to minimize layers.

ALWAYS clean up package manager caches in the same RUN layer as the install.

---

Shell Form vs Exec Form

Three instructions support both forms: RUN, CMD, ENTRYPOINT.

FormSyntaxShell ProcessingVariable ExpansionSignal Handling
ShellCMD command arg1Yes (/bin/sh -c)Yes ($VAR works)App is NOT PID 1
ExecCMD ["command", "arg1"]No (direct exec)No (use ENV for vars)App IS PID 1

ALWAYS use exec form for CMD and ENTRYPOINT in production images.

Use shell form for RUN when you need variable expansion, pipes, or command chaining.

---

CMD vs ENTRYPOINT Interaction Matrix

No ENTRYPOINTENTRYPOINT (shell form)ENTRYPOINT (exec form)
No CMDError -- no command/bin/sh -c entrypoint_cmdentrypoint_cmd
CMD (exec form)cmd_executable args/bin/sh -c entrypoint_cmd (CMD ignored)entrypoint_cmd cmd_args
CMD (shell form)/bin/sh -c cmd_string/bin/sh -c entrypoint_cmd (CMD ignored)entrypoint_cmd /bin/sh -c cmd_string

Best practice pattern:

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["default-command"]
  • ENTRYPOINT (exec form) sets the fixed executable.
  • CMD (exec form) provides default arguments, overridable via docker run.
  • Shell form ENTRYPOINT ALWAYS ignores CMD -- NEVER combine them.

---

COPY vs ADD Decision Guide

Use CaseInstructionWhy
Copy local filesCOPYExplicit, predictable, no side effects
Copy from build stageCOPY --fromOnly option for multi-stage copies
Download remote file with checksumADD --checksumIntegrity verification built in
Clone a Git repositoryADD (Git URL)Supports branch/tag/commit references
Extract a local tar archiveADDAuto-extracts tar, tar.gz, tar.bz2, tar.xz
Everything elseCOPYALWAYS prefer COPY by default

ALWAYS prefer COPY unless you specifically need ADD's extra features.

---

ENV vs ARG Comparison

PropertyENVARG
Available during buildYesYes
Available at runtimeYesNo
Visible in final imageYes (docker inspect)No
Visible in historyYesYes (NEVER put secrets here)
Overridabledocker run --envdocker build --build-arg
ScopeCurrent + subsequent stagesCurrent stage only
Creates layerYesNo
Survives FROMYes (inherited)No (must re-declare)

ALWAYS use ARG for build-time-only values (version numbers, build flags). ALWAYS use ENV for values needed at container runtime (PATH, config).

---

HEALTHCHECK Syntax

HEALTHCHECK [OPTIONS] CMD <command>
HEALTHCHECK NONE
OptionDefaultDescription
--interval=DURATION30sTime between checks
--timeout=DURATION30sMax time for single check
--start-period=DURATION0sGrace period on startup
--retries=N3Consecutive failures before unhealthy

Exit codes: 0 = healthy, 1 = unhealthy, 2 = reserved (NEVER use).

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD curl -f http://localhost:8080/health || exit 1

ALWAYS set --start-period for applications with slow startup.

---

ONBUILD Triggers

ONBUILD ADD . /app/src
ONBUILD RUN /app/src/compile.sh
  • NOT executed in the current build -- fires in child images using FROM <this-image>.
  • Useful for language-stack base images.
  • ONBUILD ONBUILD is NOT allowed (no chaining).
  • ONBUILD FROM and ONBUILD MAINTAINER are NOT allowed.

---

RUN Mount Types (BuildKit)

Mount TypePurposeKey Flags
--mount=type=cachePersist package manager cachestarget, sharing, id
--mount=type=bindMount context without COPY layertarget, from, source
--mount=type=secretAccess secrets without baking inid, target, env
--mount=type=sshForward SSH agentid
--mount=type=tmpfsTemporary filesystemtarget

See references/instructions.md for complete mount syntax and examples.

---

Variable Substitution

Supported in: ADD, COPY, ENV, EXPOSE, FROM, LABEL, STOPSIGNAL, USER, VOLUME, WORKDIR, ONBUILD.

NOT supported in: RUN exec form, CMD exec form, ENTRYPOINT exec form (use shell form or ENV).

ModifierExampleResult
Default value${VAR:-default}Use default if VAR unset
Alternate value${VAR:+alternate}Use alternate if VAR is set
Remove prefix${VAR#pattern}Remove shortest prefix match
Remove suffix${VAR%pattern}Remove shortest suffix match

---

Reference Links

  • references/instructions.md -- Complete syntax and parameters for all 17 instructions
  • references/examples.md -- Production-ready Dockerfile examples for common scenarios
  • references/anti-patterns.md -- Instruction misuse patterns with corrections

Official Sources

  • https://docs.docker.com/reference/dockerfile/
  • https://docs.docker.com/build/building/best-practices/
  • https://docs.docker.com/build/building/multi-stage/
  • https://docs.docker.com/build/buildkit/

Related skills

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.