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
For that, you can use create_host_path
, like so:
version: "3.9"
services:
foo:
image: an_image
volumes:
- source: ./logs
target: /tmp/data
type: bind
bind:
create_host_path: true
Reference: Long syntax:
create_host_path: Creates a directory at the source path on host if there is nothing present. Compose does nothing if there is something present at the path. This is automatically implied by short syntax for backward compatibility with docker-compose legacy.