Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

docker run or compose cannot mount a host folder that is not there

Errordocker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /dev/noexist

Short 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.

  • Applies to Docker Engine 28, Docker Compose v2, Docker Desktop
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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/error
  2. 2Match what you see, then jump to its fix

    1. 1The error names bind source path does not exist, and the command uses --mount type=bind.--mount does not create a missing source folderFix
    2. 2A 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. 3Docker 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

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/data

2Fix

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/data

3Verify

The container starts and lists the mounted folder.

ls -ld "$PWD/data"

Confirmed by docs.docker.com

Did this fix it?

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.yaml

2Fix

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: true

3Verify

Start the stack and confirm the folder exists on the host.

docker compose up -d
ls -ld ./data

Confirmed by docs.docker.com

Did this fix it?

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/error

3Verify

Run the container again.

docker run --rm -v /path/from/the/error:/mnt alpine ls /mnt

Confirmed by docs.docker.com

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.