简体   繁体   English

如何访问 docker-compose 中的私有 GitHub 存储库?

[英]How to access private GitHub repositories in docker-compose?

This is my docker-compose.yml file:这是我的 docker-compose.yml 文件:

version: '2.1'

services:

  users-db:
    container_name: users-db
    build: git@github.com: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:这是 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:当我运行docker-compose up 时,出现以下错误:

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):问题可能与 ssh 权限有关,但我将我的 ssh 密钥作为安装卷添加到容器中(或者我在那里犯了一些错误):

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):这是 ~/.ssh 目录(我的主机)的权限:

drwx------   2 llopusina llopusina     4096 јун  7 14:22 .ssh

and these are the permissions of files in ~/.ssh (my host machine):这些是 ~/.ssh (我的主机)中文件的权限:

-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

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确保.ssh文件夹和您挂载到容器的密钥具有正确的权限(文件夹为 700,密钥文件为 600)并且所有者设置为docker:docker

EDITED: It looks like the problem of keys and context between docker daemon and the host.编辑:看起来像是 docker 守护进程和主机之间的密钥和上下文问题。 I found this unresolved issue in docker-compose : https://github.com/docker/compose/issues/2856我在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. <...> 解决方案是在客户端进行 git clone。 We don't consider it high-priority, but PRs are always welcome.我们不认为它是高优先级的,但 PR 总是受欢迎的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM