我想将我的~/.ssh
映射到docker容器.ssh
。我有码头工人组成
version: '3'
volumes:
ssh-data:
driver: local
driver_opts:
type: none
device: ~/.ssh/
o: bind
services:
mysql:
container_name: mysql
image: chagridsada/galera-mariadb
ports:
- "3306:3306"
volumes:
- "ssh-data:/app/.ssh/"
environment:
CLUSTER_NAME: galera-db-cluster
CLUSTER_JOIN:
MYSQL_ROOT_PASSWORD: dev
XTRABACKUP_PASSWORD: dev
但当我尝试运行容器时,它会出错。
$ docker-compose up -d
Creating network "training_default" with the default driver
Creating volume "training_ssh-data" with local driver
Creating mysql ... error
ERROR: for mysql Cannot start service mysql: error while mounting volume '/var/lib/docker/volumes/training_ssh-data/_data': failed to mount local volume: mount ~/.ssh/:/var/lib/docker/volumes/training_ssh-data/_data, flags: 0x1000: no such file or directory
ERROR: for mysql Cannot start service mysql: error while mounting volume '/var/lib/docker/volumes/training_ssh-data/_data': failed to mount local volume: mount ~/.ssh/:/var/lib/docker/volumes/training_ssh-data/_data, flags: 0x1000: no such file or directory
ERROR: Encountered errors while bringing up the project.
它试图与容器中的/var/lib/docker/volumes/training_ssh-data/_data
映射,但在docker-compose.yml
中它映射到/app/.ssh/
。
如果我将映射更改为~/.ssh:/app/.ssh
,那么它将正常工作,但我也必须为其他容器使用ssh-data
卷,所以我必须创建named volume
。
为什么要尝试使用/var/lib/docker/volumes/training_ssh-data/_data
进行映射?
我认为(!?(问题是您在Docker Compose中使用相对(~/.ssh
(引用,应该使用绝对引用
如果我没有记错的话,您可以在Docker Compose文件中使用环境变量,因此可以在Linux上用${HOME}/.ssh
替换~/.ssh
。