Bind Mount
https://docs.docker.com/engine/storage/bind-mounts/
Bind Mount: Sharing/Accessing directory that is on host OS.
docker run --mount type=bind,src=<host-path>,dst=<container-path>
Troublehsooting
The "Empty Directory" Docker Gotcha on macOS and Windows
The Symptom:
You try to bind-mount a host directory into a Docker container using a command like
docker run --mount type=bind,src=/path/on/host,dst=/path/in/container ...
docker run --volume /path/on/host:/path/in/container ...
The command runs successfully without any errors, but when you inspect the destination directory inside the container, it's completely empty, even though the source directory on your host machine has files.
The Cause:
On macOS and Windows, Docker doesn't run natively. It operates inside a lightweight Linux Virtual Machine (VM) for performance and compatibility. For security reasons, this VM has a "wall" around it and cannot access your computer's entire filesystem by default.
When you ask Docker to mount a directory that is outside of its pre-approved sharing list, it doesn't fail. Instead, it silently creates a new, empty directory within the VM's own filesystem and mounts that into your container. The result is an empty folder, and no error message to tell you why.
The Fix: Granting Docker Access
You must explicitly tell Docker which of your host directories it is allowed to access.
- Open Docker Desktop Settings: Click the Docker icon in your menu bar/system tray and select Settings (or Preferences).
- Navigate to File Sharing: Go to Resources > File Sharing.
- Add Your Directory: You'll see a list of paths Docker can already access (e.g.,
/Users
,/tmp
). Click the+
button and add the parent directory you want to mount from (e.g.,/Users/yourname/projects
). - Apply and Restart: Click the Apply & Restart button. Docker will restart its VM with the new permissions.
Once restarted, your docker run
command will work as expected, and the directory will be correctly mounted with all its contents.
Children
Backlinks