Vic*_*tor 5 docker docker-compose docker-volume
如何使用 docker-compose 中的 Image WORKDIR 映射卷?
我正在尝试使用
services:
my-app:
image: <image>
volumes:
- ./scripts:./scripts
Run Code Online (Sandbox Code Playgroud)
但是当我尝试执行时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
Run Code Online (Sandbox Code Playgroud)
有什么方法可以scripts在不知道该文件夹在哪里的情况下将我的文件夹映射到图像的 WORKDIR 中?
不,默认情况下没有办法做到这一点。但如果您愿意,可以使用解决方法
services:
my-app:
image: <image>
volumes:
- ./scripts:/scripts
command: bash -c "ln -s /scripts scripts && orignal command"
Run Code Online (Sandbox Code Playgroud)
但这需要您事先了解该命令。因此,要么您事先知道命令,要么事先知道 WORKDIR。
您还可以将工作目录更改为您想要的任何其他目录。如果您不想覆盖该命令,那么下面是另一个可能的选项
docker-compose up -d
docker-compose exec my-app ln -s /scripts scripts
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3712 次 |
| 最近记录: |