Reputation: 2647
This is my docker-compose.yml file:
version: '2.1'
services:
users-db:
container_name: users-db
build: [email protected]:lukalopusina/flask-microservices-users.git#master:project/db
volumes:
- '~/.ssh/github:/root/.ssh/id_rsa'
ports:
- 5435:5432 # expose ports - HOST:CONTAINER
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
healthcheck:
test: exit 0
This is Dockerfile:
FROM postgres
# Disable checking for known_hosts (maybe not working)
RUN mkdir /root/.ssh && echo "StrictHostKeyChecking no " > /root/.ssh/config
# run create.sql on init
ADD create.sql /docker-entrypoint-initdb.d
When I run docker-compose up I get following error:
Building users-db
ERROR: Error trying to use git: exit status 128 (Cloning into '/var/lib/docker/tmp/docker-build-git576570106'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
)
The problem is probably something with ssh permissions but I add my ssh key as mounted volume to container with (or maybe I made some mistake there):
volumes:
- '~/.ssh/github:/root/.ssh/id_rsa'
but still it is not working. How to solve this problem?
This is permissions of ~/.ssh directory (my host machine):
drwx------ 2 llopusina llopusina 4096 јун 7 14:22 .ssh
and these are the permissions of files in ~/.ssh (my host machine):
-rw------- 1 llopusina llopusina 3243 јун 7 14:15 github
-rw-r--r-- 1 llopusina llopusina 749 јун 7 14:15 github.pub
-rw-r--r-- 1 llopusina llopusina 1326 јун 7 14:35 known_hosts
Upvotes: 3
Views: 9171
Reputation: 179
Make sure the .ssh
folder and the key you mount to the container have correct permissions (700 on folder, 600 on the key file) and owner is set to docker:docker
EDITED:
It looks like the problem of keys and context between docker daemon and the host. I found this unresolved issue in docker-compose
:
https://github.com/docker/compose/issues/2856
Where the final recommendation is:
FYI to anyone reporting: this is a known issue. <...> the solution is to do the git clone on the client side. We don't consider it high-priority, but PRs are always welcome.
Upvotes: 1