Day 12: Linting – hadolint, dockle and ShellCheck
Goal: You check Containerfiles before the build with hadolint, finished images with dockle and the lab’s shell scripts with ShellCheck, control rules precisely and let all three stop a pipeline. · Duration: approx. 75 min · Prerequisite: Day 11
Briefing
- hadolint reads the Containerfile, not the image:
more than 60 rules of its own (
DL…) plus ShellCheck (SC…) for everyRUN. - dockle checks the finished image against the CIS
Docker Benchmark (
CIS-DI-…) and its own rules (DKL-…): root user, secrets inENV, setuid files, package caches. - ShellCheck checks shell scripts (
SC…): missing quotes,cdwithout error handling,sourcefiles that can’t be found. hadolint uses it forRUN. - All three know severity levels, exceptions per file and an exit code for the pipeline.
- dockle speaks the Docker API but ignores
DOCKER_HOST. It gets local Podman images viaDOCKLE_HOST(Podman socket) or as an archive.
Containerfile ──hadolint──► DL/SC findings ──build──► image ──dockle──► CIS/DKL findings
.hadolint.yaml · # hadolint ignore=… .dockleignore · --accept-key
*.sh ──shellcheck──► SC findings .shellcheckrc · # shellcheck disable=…
Drill 1: hadolint – install and run it
| Profile | hadolint |
|---|---|
| Task | Check Dockerfiles/Containerfiles for errors and best practices |
| Special feature | Parses the Dockerfile, additionally checks RUN lines
with ShellCheck |
| Project | github.com/hadolint/hadolint (GPL-3.0) |
| Version in this book | 2.15.1 |
source ~/ct-lab/setup/env.sh
mkdir -p ~/ct-lab/tag12 && cd ~/ct-lab/tag12
cp -R "$LAB/code/notes/." . && cp -R "$LAB/code/tag11/notes/." .
grep "^hadolint $(dpkg --print-architecture) " "$LAB/setup/tools.lock" | cut -c1-60
hadolint --versionExpected (shortened):
hadolint arm64 https://github.com/hadolint/hadolint/releases
Haskell Dockerfile Linter 2.15.1
You installed hadolint on Day 0, verified against this line from
tools.lock. Now the three real Dockerfiles:
hadolint --no-color notes-api/Dockerfile notes-web/Dockerfile notes-worker/Dockerfile
echo "Exit: $?"Expected:
notes-web/Dockerfile:25 DL3066 info: Non-numeric user-id may not be resolvable by
host system
Exit: 0
Format: file:line rule severity: text.
USER node is a name; whether it can be resolved on the
host, hadolint doesn’t know – just a hint. Exit 0, because the
.hadolint.yaml in the project folder only fails from
warning upward.
Save your progress? Sign up for free
Drill 2: Rules on a broken Containerfile
cat > notes-api/Containerfile.lint <<'EOF'
# notes-api/Containerfile.lint – state at end of Day 12 (deliberately faulty)
FROM golang:latest
RUN apt-get update && apt-get install -y curl
ADD . /src
RUN cd /src && go build -o /usr/local/bin/notes-api . \
&& chmod 755 $(which notes-api)
FROM quay.io/example/runtime:1.0
COPY --from=0 /usr/local/bin/notes-api /notes-api
USER root
CMD /notes-api
EOF
hadolint --no-color notes-api/Containerfile.lint; echo "Exit: $?"Expected (texts shortened):
notes-api/Containerfile.lint:2 DL3007 warning: Using latest is prone to errors …
notes-api/Containerfile.lint:3 DL3015 info: Avoid additional packages by specifying
`--no-install-recommends`
notes-api/Containerfile.lint:3 DL3008 warning: Pin versions in apt get install. …
notes-api/Containerfile.lint:4 DL3020 error: Use COPY instead of ADD for files and
folders
notes-api/Containerfile.lint:5 DL3003 warning: Use WORKDIR to switch to a directory
notes-api/Containerfile.lint:5 SC2046 warning: Quote this to prevent word splitting.
notes-api/Containerfile.lint:7 DL3026 error: Use only an allowed registry in the FROM
image
notes-api/Containerfile.lint:9 DL3002 error: Last USER should not be root
notes-api/Containerfile.lint:9 DL3066 info: Non-numeric user-id may not be resolvable
by host system
notes-api/Containerfile.lint:10 DL3025 error: Use arguments JSON notation for CMD and
ENTRYPOINT arguments
Exit: 1
Nine DL rules and one from ShellCheck (SC2046:
$(which …) unquoted). Two findings come from the project
configuration: DL3026, because quay.io isn’t
listed under trustedRegistries, and error
instead of warning for
DL3002/DL3025 via override. Every
rule is explained in the wiki:
github.com/hadolint/hadolint/wiki/DL3020.
The severity levels from top to bottom: error,
warning, info, style.
--failure-threshold (short -t) determines from
which level the exit code becomes 1:
hadolint -t error notes-api/Containerfile.lint >/dev/null; echo "Exit: $?"
hadolint --no-fail notes-api/Containerfile.lint >/dev/null; echo "Exit: $?"Expected:
Exit: 1
Exit: 0
--no-fail reports everything but never aborts – good for
introducing it into an existing project. (Careful: in testing,
-t none still returned exit 1.)
Save your progress? Sign up for free
Drill 3: Controlling rules – comment, flag, configuration
Three levels, from narrow to broad. A comment directly above the line – applies only to the following instruction:
sed -i '3i # hadolint ignore=DL3008,DL3015' notes-api/Containerfile.lint
sed -n '2,4p' notes-api/Containerfile.lint
hadolint --no-color notes-api/Containerfile.lint | grep -c ':4 DL30'
hadolint --no-color --disable-ignore-pragma notes-api/Containerfile.lint \
| grep -c ':4 DL30'Expected:
FROM golang:latest
# hadolint ignore=DL3008,DL3015
RUN apt-get update && apt-get install -y curl
0
2
--disable-ignore-pragma overrides all comments – that
way a strict pipeline checks what developers suppress locally. A
flag for one run: --ignore DL3059.
Configuration for the project: the
.hadolint.yaml gets an ignored list.
cat > .hadolint.yaml <<'EOF'
# .hadolint.yaml – Stand Ende Tag 12: gilt, wenn hadolint im Projektordner läuft
failure-threshold: warning
override:
error:
- DL3002 # letzter USER ist root
- DL3025 # CMD/ENTRYPOINT in Shell-Form
ignored:
- DL3059 # mehrere RUN hintereinander: die Layer misst dive (Tag 11)
trustedRegistries:
- docker.io
- gcr.io
- ghcr.io
EOF
hadolint --no-color notes-api/Containerfile.schlecht; echo "Exit: $?"Expected:
notes-api/Containerfile.schlecht:3 DL3018 warning: Pin versions in apk add. Instead
of `apk add <package>` use `apk add <package>=<version>`
notes-api/Containerfile.schlecht:3 DL3019 info: Use the `--no-cache` switch to avoid
the need to use `--update` and remove `/var/cache/apk/*` when done installing packages
Exit: 1
Without ignored, you would additionally see two
DL3059 hints here for the three RUNs in a row.
hadolint looks for the configuration in the current folder, then under
~/.config/hadolint.yaml; -c file selects it
explicitly.
hadolint checks labels too – as a one-off check via a flag:
hadolint --no-color --require-label org.opencontainers.image.source:url \
notes-api/Dockerfile notes-web/Dockerfile | cut -c1-72Expected:
notes-api/Dockerfile:7 DL3049 info: Label `org.opencontainers.image.sour
notes-api/Dockerfile:13 DL3049 info: Label `org.opencontainers.image.sou
notes-web/Dockerfile:15 DL3049 info: Label `org.opencontainers.image.sou
notes-web/Dockerfile:25 DL3066 info: Non-numeric user-id may not be reso
notes-web has no labels at all. In notes-api they are missing in the
stages base (line 7) and test (line 13) –
hadolint checks every stage, even those that are never shipped. That’s
why label-schema isn’t in the project file here.
Save your progress? Sign up for free
Drill 4: Formats for pipelines
-f knows tty (default), json,
sarif, checkstyle, codeclimate,
gitlab_codeclimate, gnu, codacy,
sonarqube and junit:
hadolint -f json notes-api/Containerfile.lint | jq -c '.[0]'
hadolint -f sarif notes-api/Containerfile.lint -o lint.sarif; echo "Exit: $?"
jq -c '{v: .version, tool: .runs[0].tool.driver.name,
n: (.runs[0].results | length)}' lint.sarifExpected:
{"code":"DL3007","column":1,"file":"notes-api/Containerfile.lint","level":"warning",
"line":2,"message":"Using latest is prone to errors if the image will ever update. Pin
the version explicitly to a release tag"}
Exit: 1
{"v":"2.1.0","tool":"Hadolint","n":8}
GitHub code scanning and many IDEs read SARIF 2.1.0 directly; GitLab
wants gitlab_codeclimate. The exit code does not depend on
the format.
Save your progress? Sign up for free
Drill 5: dockle – install it, first finding
| Profile | dockle |
|---|---|
| Task | Check finished images against security and best-practice rules |
| Special feature | CIS Docker Benchmark plus checks of its own; reads Docker API, registry, archive |
| Project | github.com/goodwithtech/dockle (Apache-2.0) |
| Version in this book | 0.4.15 |
dockle --version
dockle --no-color docker.io/library/nginx:1.30.6-alpine | cut -c1-80Expected (shortened):
dockle version 0.4.15
FATAL - CIS-DI-0010: Do not store credential in environment variables/files
* Suspicious ENV key found : KEY_SHA512 on RUN /bin/sh -c set -x && addgr
WARN - CIS-DI-0001: Create a user for the container
* Last user should not be root
INFO - CIS-DI-0005: Enable Content trust for Docker
* export DOCKER_CONTENT_TRUST=1 before docker pull/build
INFO - CIS-DI-0006: Add HEALTHCHECK instruction to the container image
* not found HEALTHCHECK statement
dockle read the image directly from Docker Hub – without Podman. The
FATAL finding is a false positive: KEY_SHA512 is the
checksum of the nginx signing key, not a secret. You exclude such names
with --accept-key. --exit-code 1 (short
-c) makes dockle pipeline-ready:
dockle --no-color --accept-key KEY_SHA512 --exit-code 1 \
docker.io/library/nginx:1.30.6-alpine | grep -E '^(FATAL|WARN)'; \
echo "Exit: ${PIPESTATUS[0]}"Expected:
WARN - CIS-DI-0001: Create a user for the container
Exit: 1
nginx runs as root (the master process only switches to the user
nginx later). The level at which dockle fails is set by
--exit-level (default WARN).
Save your progress? Sign up for free
Drill 6: How dockle gets at Podman images
dockle --no-color localhost/notes-api:0.1.0 2>&1 | cut -c1-90Expected:
2026-10-30T22:16:36.012Z FATAL unable to initialize a image struct: failed to init
ialize source: pinging container registry localhost: Get "https://localhost/v2/": dial
dockle looks for the Docker API at /var/run/docker.sock,
finds none and takes localhost/… for a registry – it
ignores DOCKER_HOST from Day 4. Two ways out.
First, the archive:
podman save -q -o api.tar localhost/notes-api:0.1.0
dockle --no-color --input api.tar; echo "Exit: $?"
rm api.tarExpected:
SKIP - DKL-LI-0001: Avoid empty password
* failed to detect etc/shadow,etc/master.passwd
SKIP - DKL-LI-0002: Be unique UID/GROUP
* failed to detect etc/passwd
* failed to detect etc/group
INFO - CIS-DI-0005: Enable Content trust for Docker
* export DOCKER_CONTENT_TRUST=1 before docker pull/build
Exit: 0
Second, the Podman socket, which has been running
since Day 4 and speaks the Docker API. dockle wants it explicitly, as
--host or in DOCKLE_HOST:
systemctl --user is-active podman.socket
export DOCKLE_HOST="unix://$XDG_RUNTIME_DIR/podman/podman.sock"
dockle --no-color localhost/notes-api:0.1.0 | grep -E '^[A-Z]'Expected:
active
SKIP - DKL-LI-0001: Avoid empty password
SKIP - DKL-LI-0002: Be unique UID/GROUP
INFO - CIS-DI-0005: Enable Content trust for Docker
SKIP: in scratch there is no
/etc/passwd – nothing to check. dockle reads images in your
registry directly, taking the login from
~/.docker/config.json (Day 7):
dockle --no-color "$REG/notes/notes-api:0.1.0" | grep -c 'CIS-DI-0006'Expected:
0
No HEALTHCHECK finding – because you have been building with
--format docker since Day 1. Without that switch, Podman
builds in OCI format, which has no HEALTHCHECK. Try it with a throwaway
copy:
podman build --build-arg VERSION=0.1.0 -t localhost/notes-api:0.1.0-oci \
"$NOTES/notes-api" 2>&1 | awk '/not supported/ && !n++' | cut -c1-88
dockle --no-color localhost/notes-api:0.1.0-oci | grep -A1 'CIS-DI-0006'
podman rmi localhost/notes-api:0.1.0-oci >/dev/nullExpected:
time="2026-10-30T22:20:23Z" level=warning msg="HEALTHCHECK is not supported for OCI imag
INFO - CIS-DI-0006: Add HEALTHCHECK instruction to the container image
* not found HEALTHCHECK statement
Podman only warns and keeps building. dockle notices the loss – a good reason not to leave the image format in the pipeline to chance.
Save your progress? Sign up for free
Drill 7: Findings on the notes images
dockle --no-color localhost/notes-api:schlecht | grep -E '^[A-Z]'
dockle --no-color localhost/notes-worker:0.1.0 | grep -A1 -E '^(FATAL|WARN|INFO)' \
| cut -c1-80 | head -9Expected:
FATAL - DKL-DI-0004: Use "apk add" with --no-cache
WARN - CIS-DI-0001: Create a user for the container
INFO - CIS-DI-0005: Enable Content trust for Docker
INFO - CIS-DI-0006: Add HEALTHCHECK instruction to the container image
INFO - DKL-LI-0003: Only put necessary files
FATAL - DKL-DI-0005: Clear apt-get caches
* Use 'rm -rf /var/lib/apt/lists' after 'apt-get install|update' : RUN /bin/sh
INFO - CIS-DI-0005: Enable Content trust for Docker
* export DOCKER_CONTENT_TRUST=1 before docker pull/build
INFO - CIS-DI-0006: Add HEALTHCHECK instruction to the container image
* not found HEALTHCHECK statement
INFO - CIS-DI-0008: Confirm safety of setuid/setgid files
* setgid file: grwxr-xr-x usr/sbin/unix_chkpwd
The bad image runs as root, leaves the apk cache behind and, with the
complete Go SDK, also contains its example Dockerfiles
(DKL-LI-0003). For the worker, DKL-DI-0005 is
a false positive: the finding comes from python:3.15-slim,
which cleans up with apt-get dist-clean – a command dockle
0.4.15 doesn’t know. CIS-DI-0008 lists su,
passwd, mount & co. with the setuid bit
from Debian – a candidate for hardening, not an acute error.
Deliberately accepted checks belong in .dockleignore in
the current folder – with a reason:
cat > .dockleignore <<'EOF'
# .dockleignore – state at end of Day 12: deliberately accepted dockle checks
# Docker Content Trust doesn't exist in Podman; signing happens on Day 14 with cosign
CIS-DI-0005
# python:3.15-slim cleans up with "apt-get dist-clean", which dockle 0.4.15 doesn't know
DKL-DI-0005
EOF
dockle --no-color -c 1 localhost/notes-worker:0.1.0 | grep -E '^[A-Z]'
echo "Exit: ${PIPESTATUS[0]}"
dockle --no-color -c 1 localhost/notes-api:schlecht >/dev/null; echo "Exit: $?"Expected:
INFO - CIS-DI-0006: Add HEALTHCHECK instruction to the container image
INFO - CIS-DI-0008: Confirm safety of setuid/setgid files
Exit: 0
Exit: 1
For a single run, the same works with -i CIS-DI-0005.
For the pipeline there are, as with hadolint, -f json and
-f sarif:
dockle -f json localhost/notes-api:0.1.0 | jq -c '.summary'Expected:
{"fatal":0,"warn":0,"info":0,"skip":2,"pass":14}
Save your progress? Sign up for free
Drill 8: ShellCheck – a script with errors
| Profile | ShellCheck |
|---|---|
| Task | Statically check shell scripts (bash, sh, dash, ksh) for errors |
| Special feature | Every finding with an SC… code, explanation and
suggestion; also built into hadolint |
| Project | github.com/koalaman/shellcheck (GPL-3.0) |
| Version in this book | 0.11.0 (Ubuntu package, matches the current release) |
You installed ShellCheck on Day 0 with apt. A small
script is supposed to push all notes images to the registry – with
typical mistakes:
cd ~/ct-lab/tag12
dpkg -l shellcheck | tail -1 | awk '{print $2, $3}'
cat > push-alle.sh <<'EOF'
#!/bin/bash
# push-alle.sh – state at end of Day 12 (deliberately faulty)
source ~/ct-lab/setup/env.sh
ziel=$1
cd $LAB/tag12
for img in $(podman images --format '{{.Repository}}:{{.Tag}}' | grep notes); do
podman push $img $REG/$ziel/${img##*/}
done
echo "fertig: $(ls $LAB/tag12 | wc -l) Dateien im Ordner"
EOF
shellcheck push-alle.sh; echo "Exit: $?"Expected (shortened):
shellcheck 0.11.0-2
In push-alle.sh line 3:
source ~/ct-lab/setup/env.sh
^-------------------^ SC1090 (warning): ShellCheck can't follow non-constant
source. Use a directive to specify location.
In push-alle.sh line 5:
cd $LAB/tag12
^-----------^ SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd
fails.
^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
cd "$LAB"/tag12 || exit
In push-alle.sh line 7:
podman push $img $REG/$ziel/${img##*/}
^--^ SC2086 (info): Double quote to prevent globbing and word splitting.
…
In push-alle.sh line 9:
echo "fertig: $(ls $LAB/tag12 | wc -l) Dateien im Ordner"
^-----------^ SC2012 (info): Use find instead of ls to better handle
non-alphanumeric filenames.
…
Exit: 1
Each finding shows the location, the code and a suggestion. The most
important ones: SC2164 – if cd fails, the
script keeps pushing in the wrong folder. SC2086 –
$ziel (the target) containing spaces falls apart into
several words. SC1090 – ShellCheck can’t follow the
path with ~, so it doesn’t check env.sh along
with it. Every code is explained at shellcheck.net/wiki/SC2086. The
cleaned-up version:
cat > push-alle.sh <<'EOF'
#!/bin/bash
# push-alle.sh – state at end of Day 12 (cleaned up)
# shellcheck source=../setup/env.sh
source ~/ct-lab/setup/env.sh
ziel=$1
cd "$LAB/tag12" || exit 1
for img in $(podman images --format '{{.Repository}}:{{.Tag}}' | grep notes); do
podman push "$img" "$REG/$ziel/${img##*/}"
done
echo "fertig: $(find . -maxdepth 1 -type f | wc -l) Dateien im Ordner"
EOF
shellcheck push-alle.sh; echo "Exit: $?"
shellcheck -x push-alle.sh; echo "Exit: $?"Expected:
In push-alle.sh line 4:
source ~/ct-lab/setup/env.sh
^-------------------^ SC1091 (info): Not following: ../setup/env.sh was not
specified as input (see shellcheck -x).
For more information:
https://www.shellcheck.net/wiki/SC1091 -- Not following: ../setup/env.sh wa...
Exit: 1
Exit: 0
The directive # shellcheck source=… says which file is
behind the source (relative to the current folder).
ShellCheck may only follow it with -x – then it checks
env.sh as well and knows $LAB and
$REG from there. Exit 0: no findings.
Save your progress? Sign up for free
Drill 9: Lab scripts, exceptions and formats
Now the scripts you wrote yourself, from the lab folder:
cd ~/ct-lab
shellcheck tag07/run-registry.sh tag12/push-alle.sh; echo "Exit: $?"Expected (shortened):
In tag12/push-alle.sh line 4:
source ~/ct-lab/setup/env.sh
^-------------------^ SC1091 (info): Not following: ../setup/env.sh was not
specified as input (see shellcheck -x).
For more information:
https://www.shellcheck.net/wiki/SC1091 -- Not following: ../setup/env.sh wa...
Exit: 1
Only a hint (info): without -x, ShellCheck
doesn’t follow the source. run-registry.sh
already passes; it has carried the directive
# shellcheck source=/dev/null since Day 7. Instead of
passing -x on every call, the lab folder gets a
.shellcheckrc – ShellCheck searches for it upward from the
script:
cat > .shellcheckrc <<'EOF'
# ~/ct-lab/.shellcheckrc – state at end of Day 12: resolve source paths relative to the script
source-path=SCRIPTDIR
external-sources=true
EOF
shellcheck tag07/run-registry.sh tag12/push-alle.sh; echo "Exit: $?"Expected:
Exit: 0
source-path=SCRIPTDIR resolves paths relative to the
script, external-sources=true acts like -x.
You exclude a single line with a directive above it, such as
# shellcheck disable=SC2086; before the first line of code,
it applies to the whole file.
For the pipeline: -S sets the minimum severity
(error, warning, info,
style), -f the format. The faulty version from
Drill 8 is in the companion code:
cp "$LAB/code/tag12/push-alle.sh" tag12/push-alle-kaputt.sh
shellcheck -S warning -f gcc tag12/push-alle-kaputt.sh; echo "Exit: $?"
shellcheck -f json1 tag12/push-alle-kaputt.sh | jq -c '.comments[] | [.line, .code]' \
| tr '\n' ' '; echoExpected:
tag12/push-alle-kaputt.sh:3:8: warning: ShellCheck can't follow non-constant source.
Use a directive to specify location. [SC1090]
tag12/push-alle-kaputt.sh:5:1: warning: Use 'cd ... || exit' or 'cd ... || return' in
case cd fails. [SC2164]
Exit: 1
[3,1090] [5,2164] [5,2086] [7,2086] [7,2086] [7,2086] [7,2086] [9,2012] [9,2086]
Almost every editor and CI understands -f gcc,
json1 is for your own evaluations; there are also
checkstyle and diff (suggestions as a patch).
With -S warning, the info findings drop out;
the exit code stays 1 because of the two warnings.
And hadolint? It checks every RUN with exactly this
ShellCheck – the same code as in the script:
cd ~/ct-lab/tag12
cat > Containerfile.sc <<'EOF'
FROM docker.io/library/alpine:3.24
RUN for f in /etc/*.conf; do echo $f; done
EOF
hadolint --no-color Containerfile.sc; echo "Exit: $?"
rm Containerfile.scExpected:
Containerfile.sc:2 SC2086 info: Double quote to prevent globbing and word splitting.
Exit: 0
Exit 0, because the .hadolint.yaml only fails from
warning upward.
Save your progress? Sign up for free
Checkpoint
The real Dockerfiles pass hadolint, Containerfile.lint
doesn’t:
cd ~/ct-lab/tag12
hadolint notes-api/Dockerfile notes-web/Dockerfile notes-worker/Dockerfile
echo "Exit: $?"
hadolint notes-api/Containerfile.lint >/dev/null; echo "Exit: $?"
grep DL3059 .hadolint.yamlExpected:
notes-web/Dockerfile:25 DL3066 info: Non-numeric user-id may not be resolvable by host…
Exit: 0
Exit: 1
- DL3059 # mehrere RUN hintereinander: die Layer misst dive (Tag 11)
notes-worker passes dockle, schlecht doesn’t:
export DOCKLE_HOST="unix://$XDG_RUNTIME_DIR/podman/podman.sock"
dockle -c 1 localhost/notes-worker:0.1.0 >/dev/null 2>&1; echo "Exit: $?"
dockle -c 1 localhost/notes-api:schlecht >/dev/null 2>&1; echo "Exit: $?"Expected:
Exit: 0
Exit: 1
Challenge
Rewrite notes-api/Containerfile.lint so that hadolint
runs through without a single finding and the built image
localhost/notes-api:lint passes
dockle -c 1.
Hint: A build stage on
golang:1.27-alpine, a runtime stage on
scratch, a numeric user.
Solution
cat > notes-api/Containerfile.lint <<'EOF'
# notes-api/Containerfile.lint – state at end of Day 12 (cleaned up)
FROM docker.io/library/golang:1.27-alpine AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -o /out/notes-api .
FROM scratch
COPY --from=build /out/notes-api /notes-api
USER 65532:65532
ENTRYPOINT ["/notes-api"]
EOF
hadolint notes-api/Containerfile.lint; echo "Exit: $?"
podman build -q --format docker -f notes-api/Containerfile.lint \
-t localhost/notes-api:lint notes-api >/dev/null 2>&1
dockle --no-color -c 1 localhost/notes-api:lint | grep -E '^[A-Z]'
echo "Exit: ${PIPESTATUS[0]}"Expected:
Exit: 0
SKIP - DKL-LI-0001: Avoid empty password
SKIP - DKL-LI-0002: Be unique UID/GROUP
INFO - CIS-DI-0006: Add HEALTHCHECK instruction to the container image
Exit: 0
The companion code code/tag12 contains the faulty
version – for practice.
Save your progress? Sign up for free
Enterprise Note
- hadolint runs before the build (fast, no image needed), dockle afterwards – both with their exit code as a gate, results as SARIF into code scanning.
- Exceptions belong versioned in the repository
(
.hadolint.yaml,.dockleignore), each with a reason; consider--disable-ignore-pragmain the pipeline. - Limit
trustedRegistriesto the internal registry or proxy – then everyFROMfrom foreign sources stands out immediately. - Use dockle only with a pinned version and your own false-positive
list: rules like
DKL-DI-0005lag behind new base images; the project releases rarely. - ShellCheck belongs in the same step as hadolint:
shellcheck -S warning -f gccover all*.shin the repository, exceptions in.shellcheckrcwith a comment. - HEALTHCHECK only exists in the Docker format; under Kubernetes,
probes take over the job, and there
CIS-DI-0006is a candidate for.dockleignore.