This error occurs when Docker cannot find the host directory or file you're trying to bind mount into a container. The source path must exist on the host before using the --mount flag.
When Docker reports "invalid mount config: bind source path does not exist," it means the directory or file you specified as the source for a bind mount doesn't exist on your host system. Unlike the `-v` flag which can auto-create missing directories, the `--mount` flag with `type=bind` requires the source path to exist beforehand. This is a deliberate design choice to prevent accidental directory creation and make mount configurations more explicit. This error commonly occurs when: - The path was misspelled or uses incorrect case sensitivity - The directory hasn't been created yet - You're referencing a path that exists on another machine (like in Docker Swarm) - The path format doesn't match your operating system's expectations - Environment variables in the path weren't expanded properly
First, check if the directory or file you're trying to mount actually exists:
# Check if path exists (Linux/macOS)
ls -la /path/to/your/directory
# On Windows (PowerShell)
Test-Path "C:\path\to\your\directory"
# Check the exact error message for the path Docker is looking for
docker run --mount type=bind,source=/path/to/mount,target=/app myimage 2>&1If the path doesn't exist, you'll see "No such file or directory" or similar output.
If the directory doesn't exist, create it before running your Docker command:
# Create directory on Linux/macOS
mkdir -p /path/to/your/directory
# Create directory on Windows (PowerShell)
New-Item -ItemType Directory -Path "C:\path\to\your\directory" -Force
# Verify it was created
ls -la /path/to/your/directoryThe -p flag creates parent directories as needed and doesn't error if the directory already exists.
If you want Docker to automatically create the directory when it doesn't exist, use the -v flag instead of --mount:
# --mount flag (requires path to exist)
docker run --mount type=bind,source=/data/app,target=/app myimage
# Error: bind source path does not exist
# -v flag (creates directory if missing)
docker run -v /data/app:/app myimage
# Works! Creates /data/app as root-owned directoryNote: Directories created by -v will be owned by root, which may cause permission issues later. It's usually better to create directories beforehand with proper ownership.
Docker doesn't expand ~ or environment variables in paths. Use full paths or shell expansion:
# This won't work - tilde not expanded
docker run --mount type=bind,source=~/data,target=/data myimage
# Solution 1: Use full path
docker run --mount type=bind,source=/home/username/data,target=/data myimage
# Solution 2: Use $HOME variable (shell expands it)
docker run --mount type=bind,source="$HOME/data",target=/data myimage
# Solution 3: Use command substitution
docker run --mount type=bind,source="$(echo ~)/data",target=/data myimage
# For environment variables, ensure they're expanded by the shell
export MY_DATA_PATH=/data/app
docker run --mount type=bind,source="$MY_DATA_PATH",target=/app myimageOn macOS and Windows, Docker Desktop must have access to the directories you want to mount:
Docker Desktop for Mac:
1. Click the Docker icon in menu bar
2. Go to Preferences > Resources > File Sharing
3. Add the parent directory of your mount path
4. Click "Apply & Restart"
Docker Desktop for Windows:
1. Right-click Docker icon in system tray
2. Select Settings > Resources > File Sharing
3. Add the drive or directory you want to share
4. Click "Apply & Restart"
# Common paths that need sharing:
# macOS: /Users, /Volumes, /private, /tmp
# Windows: C:\Users, D:\ (or other drives)
# After adding file sharing, retry your command
docker run --mount type=bind,source=/Users/me/project,target=/app myimageIn Docker Swarm mode, bind mount paths must exist on every node where the service might run:
# Check which nodes will run your service
docker node ls
# Create the directory on ALL Swarm nodes
# SSH to each node and run:
ssh node1 "mkdir -p /data/app"
ssh node2 "mkdir -p /data/app"
ssh node3 "mkdir -p /data/app"
# Or use a constraint to run only on specific nodes
docker service create \
--constraint 'node.hostname==node1' \
--mount type=bind,source=/data/app,target=/app \
myimageAlternative for Swarm: Use Docker volumes instead of bind mounts - they're replicated across nodes:
docker volume create --driver local mydata
docker service create --mount source=mydata,target=/app myimageWindows paths need special handling depending on your terminal:
PowerShell:
# Use Windows-style paths
docker run --mount type=bind,source=C:\Users\me\data,target=/app myimage
# Or with forward slashes
docker run --mount type=bind,source=C:/Users/me/data,target=/app myimageGit Bash (MinGW):
# Use Unix-style path with leading //
docker run --mount type=bind,source=//c/Users/me/data,target=/app myimage
# Or disable path conversion
MSYS_NO_PATHCONV=1 docker run --mount type=bind,source=/c/Users/me/data,target=/app myimageWSL2:
# Windows paths are mounted under /mnt
docker run --mount type=bind,source=/mnt/c/Users/me/data,target=/app myimage
# For WSL filesystem paths
docker run --mount type=bind,source=/home/me/data,target=/app myimageDocker Compose v2.35.0+ requires explicit configuration to create missing directories. Use the bind.create_host_path option:
version: '3.8'
services:
app:
image: myimage
volumes:
- type: bind
source: ./data
target: /app/data
bind:
create_host_path: true # Creates directory if missingFor older compose files using short syntax, the behavior depends on your Docker Compose version:
version: '3.8'
services:
app:
image: myimage
volumes:
- ./data:/app/data # May auto-create in older versionsIf you're getting this error with docker-compose, check your version:
docker compose version
# or
docker-compose --versionBehavior differences between -v and --mount:
The --mount flag was introduced to be more explicit and safer than -v. Key differences:
- --mount fails if source doesn't exist (intentional safety feature)
- -v creates the source directory if missing (owned by root)
- --mount syntax is more verbose but clearer about what's happening
Docker-in-Docker (DinD) considerations:
When running Docker inside Docker, bind mounts reference the outer host's filesystem, not the container's:
# Inside a DinD container, this path must exist on the HOST
docker run -v /data:/data myimage
# /data refers to the original host, not the DinD containerSELinux and bind mounts:
On SELinux-enabled systems (RHEL, CentOS, Fedora), you may need to add the :z or :Z suffix:
docker run --mount type=bind,source=/data,target=/app,bind-propagation=rslave \
-v /data:/app:z myimageRead-only bind mounts:
If the container only needs to read files, use read-only mounts to prevent accidental modifications:
docker run --mount type=bind,source=/config,target=/app/config,readonly myimage
# or
docker run -v /config:/app/config:ro myimageDebugging file sharing issues:
# List Docker's available mounts
docker info | grep -i "root dir"
# Check Docker's file sharing configuration
docker info | grep -i "file sharing"
# Test with a simple Alpine container
docker run --rm -it --mount type=bind,source=/your/path,target=/test alpine ls /testimage operating system "linux" cannot be used on this platform
How to fix 'image operating system linux cannot be used on this platform' in Docker
manifest unknown: manifest unknown
How to fix 'manifest unknown' in Docker
cannot open '/etc/passwd': Permission denied
How to fix 'cannot open: Permission denied' in Docker
Error response from daemon: failed to create the ipvlan port
How to fix 'failed to create the ipvlan port' in Docker
toomanyrequests: Rate exceeded for anonymous users
How to fix 'Rate exceeded for anonymous users' in Docker Hub