How can I map a volume using the Image WORKDIR in docker-compose?
I'm trying to use
services:
my-app:
image: <image>
volumes:
- ./scripts:./scripts
But when I try to execute docker-compose up -d
, I get the error bellow:
Cannot create container for service my-app: invalid volume spec "scripts": invalid volume specification: 'scripts': invalid mount config for type "volume": invalid mount path: 'scripts' mount path must be absolute
Is there any way to map my scripts
folder in the WORKDIR of a image without knowing where is this folder?
No there is no way to do that by default as such. But you can use a workaround if you would like
services:
my-app:
image: <image>
volumes:
- ./scripts:/scripts
command: bash -c "ln -s /scripts scripts && orignal command"
But this will require you to know the command before hand. So either you know command before hand or the WORKDIR before hand.
You can also change working directory to any other directory you want. If you don't want to override the command then another possible option is below
docker-compose up -d
docker-compose exec my-app ln -s /scripts scripts
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