Security skill · Find and fix
Docker image security review.
Review Dockerfiles, built container images, and registry practices for security issues such as root users, unpinned or untrusted base images, secrets baked into layers or build arguments, excess packages and tools, writable and privileged runtime settings, and missing vulnerability scanning, then harden with multi-stage builds and verify by inspecting the built image. Use when auditing a Dockerfile, an image that ships to production, or a pull request that changes a container build.
Facts
- Category
- Find and fix
- License
- MIT
- Tags
- Misconfiguration
- Version
- 1.0.0
- Last updated
- 2026-12-02
- Folder
docker-image-security-review/- MCP resource
skill://docker-image-security-review/SKILL.md- Files
- SKILL.md
- LICENSE
- references/docker-checks.md
Original Saasment content. Saasment is in early access; this skill does not require joining it.
Install via MCP or as files
Connect your client to https://www.saasment.com/api/mcp (see client setup) and call get_skill:
{
"name": "get_skill",
"arguments": {
"slug": "docker-image-security-review"
}
}Or download the .zip and unpack it into your agent's skills directory:
Terminal, from your project root (user-level: ~/.cursor/skills)
mkdir -p .cursor/skills
curl -fsSL https://www.saasment.com/ai-security/skills/docker-image-security-review/download.zip -o /tmp/docker-image-security-review.zip
unzip -o /tmp/docker-image-security-review.zip -d .cursor/skills
# result: .cursor/skills/docker-image-security-review/SKILL.mdReview SKILL.md before enabling a skill. Skills are instructions your agent will follow.
SKILL.md
---
name: docker-image-security-review
description: Review Dockerfiles, built container images, and registry practices for security issues such as root users, unpinned or untrusted base images, secrets baked into layers or build arguments, excess packages and tools, writable and privileged runtime settings, and missing vulnerability scanning, then harden with multi-stage builds and verify by inspecting the built image. Use when auditing a Dockerfile, an image that ships to production, or a pull request that changes a container build.
license: MIT
metadata:
author: Saasment
version: "1.0.0"
category: both
tags: "misconfiguration"
---
# Docker image security review (find and fix)
License: MIT. Copyright (c) 2026 Saasment. Source: https://www.saasment.com/ai-security/skills/docker-image-security-review
A container image is the thing you actually deploy, so its contents matter more than the Dockerfile that produced it. Risk comes from three places: what is inside (base image, packages, leftover tools, secrets in layers), how it is configured (user, filesystem, entrypoint, exposed ports), and where it comes from (tags that move, registries nobody checks). This skill reviews all three and verifies the result on the built image. For Kubernetes runtime settings, continue with `kubernetes-helm-manifest-review`.
## When to use
- You audit a Dockerfile, Compose file, or the images a service ships.
- A pull request changes a base image, build arguments, or the build pipeline.
- A scan found vulnerabilities in an image and you need to decide what to change.
## Safe by default
- Review only images and registries you own or are authorized to assess. Build in a local or CI environment with no production credentials.
- Do not run an image you do not trust on a machine that holds credentials. Inspect it with `docker image inspect`, `docker history`, and a scanner; if you must run it, use an isolated environment without secrets, without host mounts, and without network access.
- Never print or store a secret found in a layer. Record the layer and file only, then rotate it (see `secrets-in-repo-scan-and-rotation`).
- Do not push test images to shared registries, and do not scan third-party private images without permission.
## Procedure
1. **Inventory.** List each Dockerfile and Compose file, the images built from them, base images and tags, where images are stored, and which environments run them. Commands are in `references/docker-checks.md`.
2. **Check the base image.** Official or otherwise trusted source; a small base (distroless or minimal variants) where it fits; tag pinned to an exact version and, for production, a digest; a rebuild schedule so base image fixes arrive; no `latest`.
3. **Check the user.** The final stage sets a non-root `USER` with a numeric id; files that the app writes are owned by that user; no `sudo` or setuid helpers left in the image.
4. **Check for secrets.** No credentials in `ENV`, `ARG`, `COPY`d files (`.env`, key files, cloud credentials), or `RUN` commands; build-time secrets use BuildKit secret mounts or SSH mounts, which do not persist in layers; a `.dockerignore` excludes `.git`, environment files, and local config. Remember that deleting a file in a later layer does not remove it from an earlier one.
5. **Check build hygiene.** Multi-stage builds so compilers, package caches, and test tools do not reach the final image; package installs pinned or from a lock file; `apt-get` style installs use no-recommends and clean caches in the same layer; `curl | sh` installers avoided or checksum-verified; `ADD` from URLs avoided in favor of `COPY` and verified downloads.
6. **Check runtime configuration.** Only the needed ports are exposed; a `HEALTHCHECK` where useful; no SSH server; the entrypoint runs the app directly, not a shell script that accepts arbitrary input; the app can run with a read-only root filesystem, dropped capabilities, and no privilege escalation.
7. **Scan the built image.** Run a vulnerability scanner and a misconfiguration scanner on the image, and generate a software bill of materials. Triage findings by exploitability and fix availability (see `dependency-cve-triage-and-patch`).
8. **Check supply chain controls.** Images are built in CI, not on laptops; they are signed and verified before deploy where your platform supports it; the registry limits who can push and overwrite tags; base images and build tools are pinned.
9. **Fix.** Switch to a smaller pinned base, add a non-root user, move to multi-stage builds, use secret mounts, add `.dockerignore`, rebuild, and rotate any exposed secret.
10. **Prevent regressions.** Add a Dockerfile linter and image scan to CI with failure thresholds, and enforce registry and tag rules with an admission policy or registry setting.
## Verification
- Confirm the user: run `docker image inspect <image> --format '{{.Config.User}}'` and expect a non-root value; in an isolated test run, `docker run --rm <image> id` shows a non-zero uid.
- Confirm no secrets in layers: inspect `docker history --no-trunc <image>` for `ENV` and `ARG` values and run a secret scanner against the image or its exported filesystem; expect no matches.
- Confirm the image is smaller or leaner: compare size and package count before and after (`docker image ls`, and the SBOM), and confirm shells and compilers you removed are absent.
- Confirm scan results: re-run the scanner and compare to the baseline; high and critical findings you fixed are gone and none were added.
- Confirm runtime hardening: start the image in a test environment with `--read-only`, `--cap-drop ALL`, and `--security-opt no-new-privileges`, and confirm the app still works (add writable temporary volumes where needed).
- Confirm tag and digest pinning: the Dockerfile `FROM` lines show exact versions and CI fails on `latest` in a scratch branch.
## Reporting
Table: finding id, image and Dockerfile line, issue, risk, fix, verification. Add base image digest, scanner name and version, and the date of the scan, because vulnerability data changes daily.
## References
- Docker build secrets: https://docs.docker.com/build/building/secrets/
- Dockerfile reference: https://docs.docker.com/reference/dockerfile/
- Docker Engine security: https://docs.docker.com/engine/security/
- OWASP Docker Security Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html
- Companion skills: `kubernetes-helm-manifest-review`, `iac-misconfig-review`, `secrets-in-repo-scan-and-rotation`, `dependency-cve-triage-and-patch`.
Helper files
LICENSE
MIT License Copyright (c) 2026 Saasment Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
references/docker-checks.md
# Docker checks
License: MIT. Copyright (c) 2026 Saasment.
Tool flags change between versions; check `--help`. Run these in a local or CI environment without production credentials.
## Static checks on the Dockerfile
```bash
# Lint
hadolint Dockerfile
# Misconfiguration scan
trivy config .
# Quick searches
rg -n '^FROM|^USER|^ARG|^ENV|^ADD |curl .*\|\s*(sh|bash)|chmod\s+(-R\s+)?777' Dockerfile*
rg -n -i 'password|secret|token|api_key|private' Dockerfile* .dockerignore docker-compose*.y*ml
cat .dockerignore
```
## Inspect a built image (without running it)
```bash
docker build -t review-image:test .
docker image inspect review-image:test --format 'user={{.Config.User}} entrypoint={{.Config.Entrypoint}} cmd={{.Config.Cmd}} ports={{.Config.ExposedPorts}}'
docker image inspect review-image:test --format '{{json .Config.Env}}'
docker history --no-trunc review-image:test
# Vulnerabilities, secrets, and an SBOM
trivy image --scanners vuln,secret review-image:test
trivy image --format cyclonedx --output /tmp/sbom.json review-image:test
```
## Hardened Dockerfile example
```dockerfile
# Build stage: compilers and caches stay here
FROM node:22.11.0-bookworm-slim AS build # pin an exact version, or a digest for production
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build
# Final stage: only what the app needs to run
FROM node:22.11.0-bookworm-slim
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build --chown=10001:10001 /app/dist ./dist
COPY --from=build --chown=10001:10001 /app/node_modules ./node_modules
USER 10001:10001
EXPOSE 8080
HEALTHCHECK CMD ["node", "dist/healthcheck.js"]
ENTRYPOINT ["node", "dist/server.js"]
```
## Build-time secrets without leaving them in layers
```dockerfile
# syntax=docker/dockerfile:1
RUN --mount=type=secret,id=npm_token \
NPM_TOKEN="$(cat /run/secrets/npm_token)" npm ci
```
```bash
docker build --secret id=npm_token,src=./.npm_token_local .
```
The secret is available only during that `RUN` step and is not stored in the image history. Keep the local secret file out of the repository and out of the build context.
## Runtime hardening flags for a test run
```bash
docker run --rm --read-only --tmpfs /tmp \
--cap-drop ALL --security-opt no-new-privileges \
--pids-limit 200 --memory 256m \
review-image:test
```
Run only images you trust, on a machine without sensitive mounts or credentials.
## Risky patterns
| Pattern | Risk | Better |
| --- | --- | --- |
| `FROM image:latest` | Content changes without review | Exact version, digest for production |
| No `USER` line | Process runs as root | Numeric non-root user |
| `ENV API_KEY=...` or `ARG TOKEN=...` | Visible in image metadata and history | Runtime secret from the platform, or a build secret mount |
| `COPY . .` without `.dockerignore` | Pulls in `.git`, `.env`, local keys | `.dockerignore` with an allowlist mindset |
| `RUN curl ... \| sh` | Runs unverified code at build | Download, verify checksum or signature, then run |
| One stage with compilers and test tools | Larger attack surface | Multi-stage build |
| `ADD https://...` | Remote content without verification | `COPY` after a verified download |
| `chmod 777` | Any process can modify files | Specific owner and mode |
| Docker socket mounted into a container | Container can control the host's containers | Avoid, or use a narrowly scoped proxy |
Related
Companion skills
Questions
How do I install the Docker image security review skill?
Download https://www.saasment.com/ai-security/skills/docker-image-security-review/download.zip and unzip it into your agent's skills directory (for example .cursor/skills, .claude/skills, .agents/skills, or .github/skills) so that docker-image-security-review/SKILL.md exists. Or connect to https://www.saasment.com/api/mcp and call the get_skill tool with the slug docker-image-security-review.
What license is the Docker image security review skill under?
It is original Saasment content under the MIT license, stated in the SKILL.md frontmatter and in the LICENSE file in the skill folder.
Is it safe to run this skill?
A skill is a set of instructions your agent follows, so read SKILL.md first. It tells the agent to test only systems you own or are authorized to test, to use test environments and synthetic data, and to avoid destructive probes. Downloading it does not run any code on your machine.