Hi everyone, I immediately expose the problem.
I would like to mount a directory (.), however, excluding an sub directory (vendor).
In practice, I would like the latter to be managed only as an internal volume to docker.
In this regard, I created two files
+ tree -p
├── [-rw-rw-r--] bind.yml
└── [-rw-rw-r--] volume.yml
Let’s examine them
+ cat bind.yml
services:
test:
image: bash
volumes:
- type: bind
source: .
target: /app
- type: bind
source: vendor
target: /app/vendor
volumes:
vendor:
+ cat volume.yml
services:
test:
image: bash
volumes:
- type: bind
source: .
target: /app
- type: volume
source: vendor
target: /app/vendor
volumes:
vendor:
I point out the only difference
+ diff bind.yml volume.yml
8c8
< - type: bind
---
> - type: volume
We start doing some tests (let’s start with bind.yml)
+ docker compose -f bind.yml run --rm test echo OK
Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /tmp/tmp.G55luRDlaP/vendor
mmmhhh…
Let’s try again with volume.yml
+ docker compose -f volume.yml run --rm test echo OK
OK
OK, but
+ tree -p
├── [-rw-rw-r--] bind.yml
├── [drwxr-xr-x] vendor
└── [-rw-rw-r--] volume.yml
As you can see, the directory vendor was created on the host.
This thing is not good for me
As I said at the beginning, I would like this directory to be excluded, that is, that it is managed only as an internal volume to Docker (without going to dirty the file system on the host).
How can it be done?