【发布时间】:2020-10-14 19:30:20
【问题描述】:
我正在通过docker-compose 使用远程上下文部署一些 Docker 服务。我将其配置为使用 SSH:
docker context create remote --docker "host=ssh://user@my.remote.host"
docker context use remote
在远程主机上,我有多个要挂载到 Docker 的配置文件。当我尝试使用docker CLI 时,它工作正常:
docker run -v /home/user/run:/test -it alpine:3.11
# ls -la /test
-> shows remote files correctly here
但是当我使用带有配置文件的docker-compose 启动它时:
version: "3.3"
services:
nginx:
image: nginx:1.17.10-alpine
container_name: nginx
restart: unless-stopped
volumes:
- ${HOME}/run/nginx.conf:/etc/nginx/nginx.conf
ports:
- "80:80"
- "443:443"
由于某种原因,它试图挂载本地文件而不是远程文件,但失败并出现错误:
ERROR: for nginx Cannot start service nginx: OCI runtime create failed: container_linux.go:296: starting container process caused "process_linux.go:398: container init caused \"rootfs_linux.go:58: mounting \\\"/home/local-user/run/nginx.conf\\\" to rootfs \\\"/hdd/docker/overlay2/c869ef9f2c983d33245fe1b4360eb602d718786ba7d0245d36c40385f7afde65/merged\\\" at \\\"/hdd/docker/overlay2/c869ef9f2c983d33245fe1b4360eb602d718786ba7d0245d36c40385f7afde65/merged/etc/nginx/nginx.conf\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
是否可以通过类似于标准 Docker CLI 的docker-compose 挂载远程资源?
【问题讨论】:
-
如果您在远程系统上使用正确的绝对路径,我希望这会起作用;我希望在尝试联系 Docker 之前,会在本地扩展像
$HOME这样的环境变量。将docker-compose.yml复制到远程计算机并远程运行整个docker-compose up命令可能会更健壮一些。
标签: docker ssh docker-compose