Docker Compose - bind source path does not exist
Asked Answered
V

3

6

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? :)

Volta answered 14/6, 2021 at 10:1 Comment(2)
~ expansion is a feature implemented by Unix shells. If you want it anywhere else, it needs to be implemented as well. Apparently Docker Compose hasn't done it.Sungod
Wish it were this simple :( Unfortunately ${HOME} produces the same error. But thank you for pointing this out, would have been poor show to publish this if it didn't work on Windows!Volta
K
9

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

Kazimir answered 27/1, 2023 at 8:58 Comment(0)
K
2

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
Kirshbaum answered 14/6, 2021 at 10:13 Comment(2)
This ~ symbol did seem to be getting expanded for me (perhaps a mac specific thing. I've tried changing to your suggestion to be careful though, but I'm getting the same error message :( and the error is followed up by the full path I'm aiming for, which is correct.Volta
@Volta i faced the same situation, I could only resolve it by moving my project directory back to where it was originally... so the issue was caused by changing that path. Would love to understand this better so that I could move things around if I wish! let me know how you did with this, thanks!Ankus
D
0

I'm not sure if this was implemented in 2021, but currently in Docker Desktop 4.34.2 only certain directories will be shared. These can be set in Preferences > Resources > File sharing under "Virtual file shares". Some default ones are there, but the source need to be available under one of these or need to be added. See the documentation on settings.

I had this issue and solved it this way.

Detergent answered 29/9 at 7:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.