Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping volume related with WORKDIR

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?

like image 823
Victor Avatar asked Nov 08 '22 16:11

Victor


1 Answers

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
like image 83
Tarun Lalwani Avatar answered Nov 15 '22 06:11

Tarun Lalwani