与 WORKDIR 相关的映射卷
Mapping volume related with WORKDIR
如何使用 docker-compose 中的 Image WORKDIR 映射卷?
我正在尝试使用
services:
my-app:
image: <image>
volumes:
- ./scripts:./scripts
但是当我尝试执行 docker-compose up -d
时,出现以下错误:
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
有什么方法可以在不知道这个文件夹在哪里的情况下将我的 scripts
文件夹映射到图像的 WORKDIR 中?
不,默认情况下没有办法做到这一点。但如果您愿意,可以使用变通方法
services:
my-app:
image: <image>
volumes:
- ./scripts:/scripts
command: bash -c "ln -s /scripts scripts && orignal command"
但这需要您事先了解命令。所以你要么事先知道命令,要么事先知道 WORKDIR。
您还可以将工作目录更改为您想要的任何其他目录。如果您不想覆盖该命令,则下面是另一个可能的选项
docker-compose up -d
docker-compose exec my-app ln -s /scripts scripts
如何使用 docker-compose 中的 Image WORKDIR 映射卷?
我正在尝试使用
services:
my-app:
image: <image>
volumes:
- ./scripts:./scripts
但是当我尝试执行 docker-compose up -d
时,出现以下错误:
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
有什么方法可以在不知道这个文件夹在哪里的情况下将我的 scripts
文件夹映射到图像的 WORKDIR 中?
不,默认情况下没有办法做到这一点。但如果您愿意,可以使用变通方法
services:
my-app:
image: <image>
volumes:
- ./scripts:/scripts
command: bash -c "ln -s /scripts scripts && orignal command"
但这需要您事先了解命令。所以你要么事先知道命令,要么事先知道 WORKDIR。
您还可以将工作目录更改为您想要的任何其他目录。如果您不想覆盖该命令,则下面是另一个可能的选项
docker-compose up -d
docker-compose exec my-app ln -s /scripts scripts