【问题标题】:How to access private GitHub repositories in docker-compose?如何在 docker-compose 中访问私有 GitHub 存储库?
【发布时间】:2020-03-14 23:58:07
【问题描述】:

这是我的 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

这是 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

当我运行 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.
)

问题可能与 ssh 权限有关,但我将我的 ssh 密钥作为挂载卷添加到容器中(或者我在那里犯了一些错误):

volumes:
    - '~/.ssh/github:/root/.ssh/id_rsa'

但它仍然无法正常工作。如何解决这个问题?

这是 ~/.ssh 目录(我的主机)的权限:

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

这些是~/.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

【问题讨论】:

标签: git docker ssh docker-compose


【解决方案1】:

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

编辑: 看起来像是 docker daemon 和主机之间的键和上下文问题。我在docker-compose 中发现了这个未解决的问题: https://github.com/docker/compose/issues/2856

最终推荐在哪里:

仅供报告的任何人参考:这是一个已知问题。 <...> 解决方案是 在客户端执行 git clone。我们不考虑 高优先级,但始终欢迎 PR。

【讨论】:

  • 我在问题描述中添加了权限列表。我的权限有问题吗?
猜你喜欢
  • 1970-01-01
  • 2021-03-26
  • 2013-03-23
  • 2018-11-27
  • 2021-01-18
  • 2018-11-02
  • 2023-03-16
  • 1970-01-01
  • 2023-03-20
相关资源
最近更新 更多