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? :)
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With