Skip to content

docker

Dockerfiles and Compose files: Dockerfile best practices, valid Compose files, a .dockerignore beside each Dockerfile, and image vulnerability scans. Guide: Security.

A scope has file paths **/Dockerfile, **/Dockerfile.*, **/*.dockerfile, **/docker-compose*.yml, **/docker-compose*.yaml, **/compose.{yml,yaml}, **/compose.*.{yml,yaml}, or **/compose-*.{yml,yaml}, except **/*.dockerignore.

Lints every Dockerfile, and runs ShellCheck over its RUN lines.

Runs at the commit stage.

An unpinned base image makes a build nobody can repeat, and a cache left in a layer bloats the result.

Change the instruction the way the rule says.

FROM node:latest reports DL3007, because that tag moves. Pin an explicit version tag or a digest.

gspot ignore docker/hadolint --paths "<path>" --reason "<why>"
gspot ignore docker/hadolint --rule <rule> --reason "<why>"

Parses every Compose file with docker compose config, which needs no running daemon.

Runs at the push stage, once per scope.

Valid YAML can still hold a key that Compose rejects, and otherwise the first sign comes during a deploy.

Read the message Compose prints; it names the key and the service.

A Compose service with the unknown key bogus fails to parse. Remove the key, or use a supported one.

gspot ignore docker/compose --paths "<path>" --reason "<why>"

Reports each Compose service that runs privileged, mounts the Docker socket, or turns off its seccomp, AppArmor, or SELinux profile.

Runs at the commit stage.

Each of these hands the container control of the host, so one bug in the service compromises the machine.

Change the service the way the message says.

A Compose service with privileged: true reports privileged-container. Remove it, and add only the capabilities the service needs with cap_add.

Rule What it checks What to do
privileged-container No Compose service runs with privileged: true. Remove privileged, and add only the capabilities this service needs with cap_add.
docker-socket No Compose service mounts the Docker socket. Do not mount the Docker socket. A process that reads it controls the host.
unconfined-profile No Compose service turns off its seccomp, AppArmor, or SELinux profile. Keep the default seccomp, AppArmor, and SELinux profiles, or name a profile that allows what you need.
gspot ignore docker/service-security --paths "<path>" --reason "<why>"
gspot ignore docker/service-security --rule privileged-container --reason "<why>"

Finds RUN lines that can rewrite the lockfile, pipe a download into a shell, or add a second Python index, an ADD of a URL with no checksum, the Docker socket as a VOLUME, an nginx tag with no full version, and a shell as the ENTRYPOINT.

Runs at the commit stage.

A build that rewrites its lockfile or runs a downloaded script ships code that nobody reviewed, and a shell as process 1 swallows the stop signal.

Apply the fix that the message names.

RUN npm install reports lockfile-install. Write RUN npm ci, which installs the lockfile as it is.

Rule What it checks What to do
lockfile-install No RUN installs packages in a way that can rewrite the lockfile. Install with npm ci, pnpm install --frozen-lockfile, or the locked mode of the package manager.
piped-download No RUN pipes a download into a shell or an interpreter. Fetch a fixed version to a file, compare its checksum, and run the file.
nginx-tag A FROM of nginx pins a full version tag or a digest. Use a tag with major, minor, and patch versions, or pin the digest.
shell-entrypoint An ENTRYPOINT in exec form starts the program itself, not a shell. Name the program as the first element, such as ENTRYPOINT ["node", "server.js"].
extra-index-url No RUN installs Python packages from a second index. Serve every package from one index, such as a proxy of the public index, and pass it with --index-url.
remote-add An ADD of a URL checks the hash of what it downloads. Add --checksum=sha256:<hash> to the ADD, or download the file in a RUN and compare its hash.
docker-socket No VOLUME names the Docker socket. Remove the socket. Give the job that needs Docker its own builder or a rootless daemon.
gspot ignore docker/instructions --paths "<path>" --reason "<why>"
gspot ignore docker/instructions --rule lockfile-install --reason "<why>"

Checks that an ignore file beside every Dockerfile keeps .git, installed dependencies, and environment files out of the build, and that no COPY source sits in it.

Runs at the commit stage, once for the repository.

Without it, the daemon receives the whole folder, and a COPY of it puts the history and secrets into the image.

Add a .dockerignore beside the Dockerfile with the paths the message names.

A Dockerfile with no .dockerignore beside it reports a finding. Add one that excludes the paths the finding names, such as .git and installed dependencies.

Rule What it checks What to do
missing-file Each Dockerfile has an ignore file, beside it or in its build context. Add a .dockerignore that lists .git, .env, and the paths that the configurations mark local.
missing-entry The ignore file lists .git, .env, and the local paths of the selected configurations. List each path that the finding names in the ignore file.
ignored-source No COPY names a source that the ignore file excludes. Remove the path from the ignore file, or remove it from the COPY.
syntax A file that the check reads parses without errors. Fix the syntax at the reported line.
gspot ignore docker/dockerignore --paths "<path>" --reason "<why>"
gspot ignore docker/dockerignore --rule missing-file --reason "<why>"

Scans Dockerfiles for HIGH and CRITICAL misconfigurations, including a root user and exposed secrets.

Runs at the push stage, once per scope.

A root user turns any bug in the service into full control of the container.

Change the file the way the message says.

A Dockerfile whose final stage runs as root reports a finding. Create an unprivileged user, and switch to it with USER before the application starts.

gspot ignore docker/trivy-config --paths "<path>" --reason "<why>"
gspot ignore docker/trivy-config --rule <rule> --reason "<why>"

Scans every image a Compose file names for known vulnerabilities in its packages.

Runs only when gspot check --only docker/trivy-image names it, once per scope, and needs a running Docker daemon.

A base image carries hundreds of packages, and new advisories keep arriving after you pick it.

Move to a newer tag of the image.

An image with a vulnerable package reports the advisory. Move to an image version with the fixed package.

gspot ignore docker/trivy-image --paths "<path>" --reason "<why>"
Setting What it sets
docker.allowed_registries The registries a base image may come from; empty allows any.
docker.severity The severities Trivy reports.
Rule file Installed when
.gspot/rules/DOCKER.md Always
Tool Version
hadolint 2.15.1
trivy 0.76.0
docker Any, install it yourself

.gspot/configurations/docker/hadolint.yml, .gspot/configurations/docker/trivy.yml, and .gspot/configurations/docker/trivyignore