Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Compose - bind source path does not exist

In my docker compose service I have the following:

volumes:
      - ~/DockerStuff/Projects:/root/Documents/Projects
      - ~/DockerStuff/Downloads:/root/Downloads

But when I run docker compose up I'm being told: Error response from daemon: invalid mount config for type "bind": bind source path does not exist

I keep seeing things saying that you can create bind volumes and if the host directory doesn't exist, Docker shall create it on the fly. But these seem specific to DockerFile setups rather than compose files.

Is such functionality possible in docker compose too? :)

like image 737
apbarratt Avatar asked May 17 '26 10:05

apbarratt


2 Answers

In order to create the host folder for the docker-compose volume binding if it doesn't exist just add bind.create_host_path to your volumes section -

volumes:
      - type: bind
        source: localFolder/subFolderIfNeeded
        target: /data
        bind:
          create_host_path: true

NOTE: Tested on Docker compose 2.15.1

like image 50
David Avikasis Avatar answered May 19 '26 02:05

David Avikasis


The ~ symbols is not expanded by docker compose.

You have to rely on this approach:

building script

HOME=${HOME} docker-compose ... command options ...

docker compose yaml

volumes:
      - ${HOME}/DockerStuff/Projects:/root/Documents/Projects
      - ${HOME}/DockerStuff/Downloads:/root/Downloads
like image 31
Antonio Petricca Avatar answered May 19 '26 00:05

Antonio Petricca