docker run or compose cannot mount a host folder that is not there
docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /dev/noexistShort answer
A bind mount needs a source folder on the host. With -v, Docker creates a missing folder for you. With --mount it does not, and it stops with a bind source path error. Create the folder first, add bind-create-src, or switch to a form that creates it.
Fix it fast
1Find out which cause you have
Check that the host path in the error really exists, as seen from the machine that runs the Docker daemon.
ls -ld /path/from/the/error2Match what you see, then jump to its fix
- 1
The error names bind source path does not exist, and the command uses --mount type=bind.--mount does not create a missing source folderFix - 2
A Compose file uses type: bind with a bind block, and the folder is missing on a fresh checkout.Compose long syntax has create_host_path turned offFix - 3
Docker cannot make the missing folder on its own, for example under a path the daemon user cannot write.The daemon is not allowed to create the folder, so it must exist alreadyFix
- 1
What does the error look like?
docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /dev/noexist
Cause 1 of 3
--mount does not create a missing source folder
1Check
Unlike -v, the --mount flag does not create the source by default; it returns an error.
docker run --rm --mount type=bind,src="$PWD/data",dst=/mnt/data alpine ls /mnt/data2Fix
Create the folder before the command, or ask Docker to create it with the bind-create-src option.
mkdir -p "$PWD/data"
docker run --rm --mount type=bind,src="$PWD/data",dst=/mnt/data,bind-create-src alpine ls /mnt/data3Verify
The container starts and lists the mounted folder.
ls -ld "$PWD/data"Confirmed by docs.docker.com
Cause 2 of 3
Compose long syntax has create_host_path turned off
1Check
The short syntax creates the folder for you. In the long syntax, create_host_path controls this and defaults to true, so a false value was set on purpose or copied from another file.
grep -n -B4 -A2 create_host_path compose.yaml2Fix
Remove the option, or set it to true, or create the folder in your setup step.
services:
app:
image: nginx
volumes:
- type: bind
source: ./data
target: /usr/share/nginx/html
bind:
create_host_path: true3Verify
Start the stack and confirm the folder exists on the host.
docker compose up -d
ls -ld ./dataConfirmed by docs.docker.com
Cause 3 of 3
The daemon is not allowed to create the folder, so it must exist already
1Check
Docker's -v behaviour is to create the host directory. If the daemon lacks permission for the parent folder, that step cannot succeed.
ls -ld "$(dirname /path/from/the/error)"2Fix
Create the directory yourself, as a user that can write the parent folder, before you start the container.
mkdir -p /path/from/the/error3Verify
Run the container again.
docker run --rm -v /path/from/the/error:/mnt alpine ls /mntConfirmed by docs.docker.com
How do I stop it coming back?
- Create bind-mount folders in the same script or Makefile target that starts the containers.
- Prefer ./relative paths that start with a dot in Compose, so they are not read as named volumes.
- Remember that with Docker Desktop the daemon runs in a Linux VM, so use paths that are shared with it.
- Use a named volume when the container owns the data and the host never needs to read it.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
A container started from inside a container sees an empty or missing mount
the files you mounted are not there in the second container
A bind mount is resolved by the Docker daemon, on the daemon's own host, not inside the container that typed the command.
3 causes, each with a fixServers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
AH00558: Apache in Docker cannot reliably determine its fully qualified domain name
Set the 'ServerName' directive globally to suppress this message
AH00558 is a warning, not a crash.
2 causes, each with a fixServers
Apache in a Docker container logs AH01114 when it proxies to a backend
AH01114: HTTP: failed to make connection to backend: api
Apache's proxy worker could not open a connection to the address in ProxyPass.
5 causes, each with a fix