I have the following docker-compose
version: "3.9"
services:
foo:
image: an_image
volumes:
- source: ./logs
target: /tmp/data
type: bind
I am using 3.9 docker-compose syntax with 2.24 docker-compose library. Because of this bug I have to use the long syntax for mounting volumes.
My goal is the following: The logs
directory does not exist in the host system. Nevertheless, I want to create this directory and mount it on the docker container. With the old binary version this was working (I was using the compact syntax ./logs:/tmp/data) but not anymore and not with the long syntax.
The error I am getting is
Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /host_mnt/Users/user/Workspace/an-app/e2e/logs
I am running docker-compose from the an-app directory
docker-compose -f ./e2e/docker-compose.e2e.yml up
2
Answers
In Docker Compose, when using the long syntax for bind mounts, the source path must exist on the host system; Docker will not create it for you. This behavior is different from the short syntax, where Docker can create the directory if it does not exist.
To work around this, you can ensure that the directory exists on the host before starting your services with Docker Compose.
For that, you can use
create_host_path
, like so:Reference: Long syntax: