Safeguard
Developer Tools•

Which host folders are safe to bind mount into a dev container?

Mount only the project folder, use read only where you can, and keep your home directory and Docker socket out. Learn how bind mounts expose the host.

Safeguard Security Team
4 min read

Mount the project folder and nothing more. Bind mounts give a container write access to host files by default, so a mounted home directory, credentials folder or Docker socket puts them within reach of every tool inside. Use the read only option wherever the container does not need to write.

What a bind mount does

A bind mount maps a host path into a container. Docker's documentation says bind mounts have write access to files on the host by default, so a process in the container can create, modify or delete important system files or directories. The same page explains that a mount over an existing container directory hides what was there, and that the only way to see it again is to recreate the container without the mount.

For a dev container this matters because the container runs your editor's server, extensions, build tools and often scripts from the repository itself.

A decision table

Candidate mountSuggested stanceReason
The project folderMount, writableThe tools need to edit it
A shared reference data folderMount read onlyNo need to write
Your whole home directoryAvoidExposes every project and dotfile to the container
A credentials or key folderAvoidAnything in the container could read it
The Docker socketAvoidGives control of the daemon, see below
A build cachePrefer a named volumeKeeps host paths out of it

The stance column is a recommendation from this post, not a quote from the documentation. The facts behind it are the default write access, the read only option and the daemon's authority.

How to write the mount safely

Docker prefers the mount flag for being explicit and says it supports every option. A read only mount looks like this:

docker run --mount type=bind,src=./reference,dst=/reference,ro IMAGE

One difference between the two syntaxes is worth knowing. If you use the volume flag with a host path that does not exist, Docker creates a directory there for you, always as a directory. The mount flag produces an error instead, which catches typos.

In devcontainer.json, the mounts property accepts values with the same fields as the Docker mount flag, so the same advice applies. See which devcontainer settings to flag in review.

The socket is a special case

Docker documents an example that mounts the Docker socket into a container. A container that can talk to the daemon can start other containers with other mounts. Read why that equals root on the host before approving it.

Permission surprises

On Linux, dev container tooling can update a container user's UID and GID to match your local user so bind mounted files have sensible ownership. The reference says updateRemoteUserUID defaults to true. If you run with user namespace remapping, Docker warns that mounts into paths the mapped user cannot write cause permission problems.

A short routine

  1. List every mount in your dev container and Compose files.
  2. Remove any that point at a home directory, key folder or socket.
  3. Switch read only candidates to read only.
  4. Replace caches with named volumes.
  5. Re-run the container and see what breaks, then fix the narrowest thing.

Safeguard can scan the dependencies in the project you mount, and you can try a free scan at gold.safeguard.sh/scan.

Quick check

Does a read only mount hide the files from the container?

No. It only blocks writing. The container can still read everything in the mounted path.

Does Docker Desktop keep bind mounts away from my machine?

No. Docker says the daemon runs in a Linux VM and uses built in mechanisms to share host paths with containers, so mounted paths are still shared.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.