docker
Dockerfiles and Compose files: Dockerfile best practices, valid Compose files, a .dockerignore beside each Dockerfile, and image vulnerability scans. Guide: Security.
Selected when
Section titled “Selected when”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.
Checks
Section titled “Checks”hadolint
Section titled “hadolint”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.
What to do
Section titled “What to do”Change the instruction the way the rule says.
Example
Section titled “Example”FROM node:latest reports DL3007, because that tag moves. Pin an explicit version tag or a digest.
Turn it off
Section titled “Turn it off”gspot ignore docker/hadolint --paths "<path>" --reason "<why>"gspot ignore docker/hadolint --rule <rule> --reason "<why>"compose
Section titled “compose”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.
What to do
Section titled “What to do”Read the message Compose prints; it names the key and the service.
Example
Section titled “Example”A Compose service with the unknown key bogus fails to parse. Remove the key, or use a supported one.
Turn it off
Section titled “Turn it off”gspot ignore docker/compose --paths "<path>" --reason "<why>"service-security
Section titled “service-security”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.
What to do
Section titled “What to do”Change the service the way the message says.
Example
Section titled “Example”A Compose service with privileged: true reports privileged-container. Remove it, and add only the capabilities the service needs with cap_add.
Lint rules
Section titled “Lint rules”| 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. |
Turn it off
Section titled “Turn it off”gspot ignore docker/service-security --paths "<path>" --reason "<why>"gspot ignore docker/service-security --rule privileged-container --reason "<why>"instructions
Section titled “instructions”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.
What to do
Section titled “What to do”Apply the fix that the message names.
Example
Section titled “Example”RUN npm install reports lockfile-install. Write RUN npm ci, which installs the lockfile as it is.
Lint rules
Section titled “Lint rules”| 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. |
Turn it off
Section titled “Turn it off”gspot ignore docker/instructions --paths "<path>" --reason "<why>"gspot ignore docker/instructions --rule lockfile-install --reason "<why>"dockerignore
Section titled “dockerignore”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.
What to do
Section titled “What to do”Add a .dockerignore beside the Dockerfile with the paths the message names.
Example
Section titled “Example”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.
Lint rules
Section titled “Lint rules”| 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. |
Turn it off
Section titled “Turn it off”gspot ignore docker/dockerignore --paths "<path>" --reason "<why>"gspot ignore docker/dockerignore --rule missing-file --reason "<why>"trivy-config
Section titled “trivy-config”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.
What to do
Section titled “What to do”Change the file the way the message says.
Example
Section titled “Example”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.
Turn it off
Section titled “Turn it off”gspot ignore docker/trivy-config --paths "<path>" --reason "<why>"gspot ignore docker/trivy-config --rule <rule> --reason "<why>"trivy-image
Section titled “trivy-image”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.
What to do
Section titled “What to do”Move to a newer tag of the image.
Example
Section titled “Example”An image with a vulnerable package reports the advisory. Move to an image version with the fixed package.
Turn it off
Section titled “Turn it off”gspot ignore docker/trivy-image --paths "<path>" --reason "<why>"Settings
Section titled “Settings”| Setting | What it sets |
|---|---|
docker.allowed_registries |
The registries a base image may come from; empty allows any. |
docker.severity |
The severities Trivy reports. |
Rules for coding agents
Section titled “Rules for coding agents”| Rule file | Installed when |
|---|---|
.gspot/rules/DOCKER.md |
Always |
Tools and versions
Section titled “Tools and versions”| Tool | Version |
|---|---|
| hadolint | 2.15.1 |
| trivy | 0.76.0 |
| docker | Any, install it yourself |
Files gspot writes
Section titled “Files gspot writes”.gspot/configurations/docker/hadolint.yml, .gspot/configurations/docker/trivy.yml, and .gspot/configurations/docker/trivyignore