Docker bind mount with symlinks inside the mounted directory
Codemia Knowledge Hub ·
A bind mount makes a host directory visible inside the container, symbolic links included. The links themselves come through as links, and the container resolves them against its own filesystem, not the host's. A link that points somewhere outside the mounted directory only works if that target path also exists in the container, for example because you bind-mount it as well.
Bind mounts versus other mount types
Docker supports several mount options:
- Volumes: Managed by Docker and can be manipulated via Docker commands.
- Bind mounts: Link a directory or file from the host directly into the container.
- tmpfs mounts: Store data in host memory.
Bind mounts are the relevant type here, because they let you pick a specific host directory to expose inside the container.
An example directory with a symlink
A symbolic link (symlink) is a file that points to another file or directory. On Unix-like systems they are often used to keep a stable path to the current version of something without moving the data.
Consider this setup on the host:
Here /data/symlink is a symbolic link to /target.
Mounting the directory with docker run
To bind mount /data:
This starts an Ubuntu container with the host's /data directory available at /app/data.
What the symlink looks like inside the container
Inside the container, you can inspect the link:
The link is resolved inside the container, so /app/data/symlink points at /target in the container's filesystem. The listing above only shows the files if /target is also available in the container (for instance, with a second --mount type=bind,source=/target,target=/target). Without that, the absolute link is broken in the container even though it works on the host. Links that point to paths inside the mounted directory keep working, because those paths exist on both sides.
Permissions, platforms and security
- Permission management: Symbolic links keep the permissions of the original files or directories. Make sure the user in the container has the permissions needed to read the targets.
- Cross-platform compatibility: Check that links resolve correctly, especially on Windows, where symbolic link behavior can differ.
- Security implications: Mounting host directories, especially ones containing symlinks, can expose more of the host filesystem to the container. Limit user permissions inside the container.
| Feature | Description | Example Usage |
| Bind Mount | Mounts a directory or file from host to container | --mount type=bind,source=...,target=... |
| Symbolic Link | File pointing to another file/directory | ln -s /source /link |
| Permission | Inherits from the pointed target | chmod on /target for /link permissions |
| Host Access | Access to more of the host's file system | Useful for apps requiring host data |
Broken, circular and network links
- Broken links: A link breaks if its target is moved or deleted. Regular checks and logging help catch this.
- Performance: Reading large amounts of data through symbolic links can add delay. Tools such as Docker stats help with performance tuning.
- Circular links: Avoid them, since they can cause infinite loops when traversed.
- Links to network storage: Symbolic links may point to automounted network storage, but DNS and network configuration then need to line up with the container's networking.
Related reading
- Mount non-existing host directory into non-root container
- Mounting directory from host machine to container in Docker
- Mounting kubernetes volume with User permission
- Mounting multiple volumes on a docker container?
- Mounts denied. The paths ... are not shared from OS X and are not known to Docker
- Multiline comments in Dockerfiles
- multiple command in postStart hook of a container
- Multiple commands on docker ENTRYPOINT
System design interview problems on this topic
- Design a Container Orchestration System: solution and walkthrough
- Design a Code Deployment System: solution and walkthrough
- Design GitHub Actions: solution and walkthrough
- Design a Serverless Architecture Framework: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.