October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

Docker Security Basics: Non-Root Users, Read-Only Filesystems, Image Scanning, and Build Secrets

A practical Docker hardening baseline: run with least privilege, make write paths deliberate, review image-scan findings, and keep build credentials out of image inputs.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A practical Docker hardening baseline combines four controls at different stages: run the service as a non-root user, make filesystem writes explicit, scan image contents for known vulnerabilities, and use temporary BuildKit mounts for credentials needed during a build. None makes a container secure by itself; each reduces a different risk and needs to fit the application’s startup and deployment requirements.

How the four Docker security controls fit together

These controls address different parts of an image’s lifecycle, so they complement rather than replace one another.

As an Amazon Associate I earn from qualifying purchases.

Practice Lifecycle stage Main purpose Compatibility check
Non-root USER Image configuration and runtime Limit privileges available to the process File ownership, ports, and startup behavior
Read-only root filesystem Container runtime Restrict writes to the root filesystem Identify paths that need a volume or temporary filesystem
Image scanning Build, release, and ongoing image review Inventory components and match them against known vulnerability data Remediation cadence for the base image and dependencies
BuildKit secret mount Image build Give a build instruction temporary access to credentials Builder support and how the build step consumes the secret

This is a practical division of responsibilities, not a ranking of products or a guarantee of security. Docker’s building best practices, build-secrets guidance, Docker Scout documentation, container run reference, and OWASP’s Docker Security Cheat Sheet describe the relevant controls.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I run a Docker container as a non-root user?

Set the intended identity with USER in the final runtime stage of the Dockerfile. Docker’s building best practices advise: “If a service can run without privileges, use USER to change to a non-root user.” The instruction affects subsequent build instructions as well as the default user when the image runs, so its position matters.

Set an identity the application can use

For example, a runtime stage might create a dedicated user and group, assign required files and directories appropriate ownership, and then declare that user with USER. The exact commands depend on the base image and application; user-creation syntax is not identical across distributions. Give the process read and write access only where it needs it, and verify that startup scripts, application files, and any required listening ports work with that identity.

If stable numeric identity matters across builds or mounted files, consider explicit UID and GID values. Docker notes that automatically assigning the next available IDs can produce different IDs after rebuilds. This matters especially when permissions are checked against numeric ownership on mounted filesystems.

Running as non-root reduces the privileges available to the process under the configured container setup. It does not remove every capability, fix unsafe daemon or host configuration, or replace other security controls.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I make a Docker container filesystem read-only?

Use docker run --read-only to make the container’s root filesystem read-only. If the application needs temporary writes, provide only the writable locations it requires. Docker documents this runtime option and writable mounts in the container run reference; OWASP illustrates a read-only filesystem with tmpfs for temporary data and read-only mounts for data that should not be changed.

Identify write paths before enabling it

Check the application’s actual startup and runtime behavior. Depending on the software, it may try to write temporary files, logs, caches, sockets, or other state. These are possibilities to investigate, not paths every application needs. A write attempt against the read-only root can cause startup or runtime failures, so validate the application in an environment representative of deployment.

A minimal example is:

docker run --read-only --tmpfs /tmp IMAGE

Replace IMAGE with the image you intend to run, and add writable mounts only for paths the application genuinely needs. A tmpfs is suitable for temporary data that need not persist; use an appropriately managed volume when data must persist. Read-only root does not make every mounted location read-only: the access mode of each mount is a separate choice. OWASP also shows the Compose setting read_only: true and read-only volume mounts in its Docker Security Cheat Sheet.

Rank #3
BookFactory Security Pass Down Log Book, Wire-O, 100 Pages
  • Made in USA - Proudly produced in Ohio by a Veteran-owned business
  • Comprehensive Coverage: This BookFactory log book includes essential fields such as post/shift, time of change, date, weather conditions, and a designated space for detailed notes. This ensures that all relevant information is captured and easily accessible.
  • Sturdy Cover: The trans-lux cover protects the log book from wear and tear, ensuring its longevity and maintaining the integrity of your recorded data.
  • Essential Security Tool: This log book is an indispensable tool for any organization that values security and accountability. It helps to prevent misunderstandings, improve communication, and ensure a smooth transition between shifts.
  • Wire-O with Trans-lux cover, 100 Pages, Dimensions 8.5" x 11" - (Security-Pass-Down) Reorder SKU: LOG-100-7CW-PP(Security-Pass-Down)

How do I scan a Docker image for vulnerabilities?

Use an image scanner as an inventory and matching step, then review what it finds. Docker Scout analyzes image contents into a software bill of materials (SBOM) and matches the identified components against a vulnerability database. Its overview is at Docker Scout.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Review findings and policy results

For each finding, check which package is affected, whether a fix is available, whether an updated base image addresses it, and whether changing the dependency is compatible with the application. A finding is not automatically a production fix, and an absence of findings does not prove that an image is vulnerability-free: results are bounded by what the tool detects and the vulnerability data available at scan time.

Docker Scout policy evaluation can check configured criteria such as critical or high vulnerabilities with fixes available, supply-chain attestations, and whether the image has a non-root default user. The policy rules are configurable. Docker’s Policy Evaluation documentation explains that docker scout policy indexes an image into an SBOM and enriches it with CVE and VEX data. Treat that policy evaluation as a specific workflow; it is not the same thing as automatic registry monitoring.

For a repeatable release process, retain timestamped, versioned scan or policy reports with CI or release records. That lets reviewers understand which image and data snapshot informed a decision. Other image scanners are also available; choose one whose coverage and workflow suit your environment.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How do I pass secrets to a Docker build without baking them into the image?

Use BuildKit secret mounts for general credentials such as tokens or passwords, or SSH mounts when a build needs an SSH agent or key, for example to access a private Git repository. Docker warns that “Build arguments and environment variables are inappropriate for passing secrets to your build, because they persist in the final image.” See the Docker build secrets guide for the supported workflow.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pass a secret only to the build instruction that needs it

  1. Make the secret available to the build. Supply the secret through the BuildKit build interface rather than placing it in the Dockerfile as an ARG or ENV value.
  2. Request a mount in the consuming instruction. Use a Dockerfile build instruction configured with a secret mount, and ensure the build frontend and builder support the feature.
  3. Keep its use scoped. Read the mounted secret only in the instruction that needs it; do not copy it into the image or print it in build output.

A secret mount provides temporary access for the duration of the build instruction. It solves the build-time credential problem, not runtime secret management: credentials the application needs after launch require a separate runtime delivery and access-control design.

Keep sensitive and irrelevant files out of the build context as well. Docker’s building best practices describe using .dockerignore to exclude files from that context. A secret that is never sent as ordinary build input is less likely to be exposed through an accidental copy.

Keep the hardening baseline current

Use maintained base images and rebuild deliberately so that security fixes can reach your image. Docker notes that tags are mutable: the same tag can refer to a different image over time. Pinning a base image by digest identifies a specific version and supports repeatability, but it also means updates require a process to notice and adopt a newer digest. See Docker’s guidance on base images, tags, and digests.

A useful workflow is to make identity, write permissions, and build-secret handling part of image construction; validate writable paths when testing runtime configuration; and scan and review the image as part of release and maintenance. Adapt each step to the application instead of assuming that a generic Dockerfile or a clean scan proves the deployment is safe.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.