I want to map my ~/.ssh
to docker container .ssh
. I have docker compose as
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
but when I try to run the container, it gives error.
$ 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.
its trying to map with /var/lib/docker/volumes/training_ssh-data/_data
in container, but in docker-compose.yml
its mapped to /app/.ssh/
.
If I change mapping to ~/.ssh:/app/.ssh
, then it will work fine, but I have to use ssh-data
volume for other container too, so I have to create named volume
.
Why its trying to map with /var/lib/docker/volumes/training_ssh-data/_data
?
I think (!?) the issue is that you're using a relative (~/.ssh
) reference within the Docker Compose and you should should use an absolute reference
If I recall correctly, you can use environment variables within Docker Compose files and so could replace ~/.ssh
with ${HOME}/.ssh
on Linux.