Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用env变量向docker发送SSH密钥无效_Docker_Ssh_Docker Compose_Dockerfile_Ssh Keys - Fatal编程技术网

使用env变量向docker发送SSH密钥无效

使用env变量向docker发送SSH密钥无效,docker,ssh,docker-compose,dockerfile,ssh-keys,Docker,Ssh,Docker Compose,Dockerfile,Ssh Keys,我试图在docker文件中安装一些私有gems(bitbucket git repo),SSH权限被拒绝 我所做的是: 将我的私钥设置为“ssh_key”env变量 将“ssh_config”环境变量设置为“IdentityFile/.ssh/id_rsa主机用户” 在docker compose中: 在Dockerfile中: 我得到了错误 fatal: Could not read from remote repository. Please make sure you have the

我试图在docker文件中安装一些私有gems(bitbucket git repo),SSH权限被拒绝

我所做的是:

  • 将我的私钥设置为“ssh_key”env变量
  • 将“ssh_config”环境变量设置为“IdentityFile/.ssh/id_rsa主机用户”
  • 在docker compose中:
  • 在Dockerfile中:
  • 我得到了错误

    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    
    但是,当我注释掉私有gems并构建映像时,ssh到容器中,删除id_rsa文件并使用文本编辑器手动粘贴主机私钥,然后运行chmod 600(或者只装载我的主机~/.ssh dir),然后就可以安装私有gems而不会出现任何错误

    我不知道到底是什么导致了这个错误。有没有更简单的方法来实现这一点

    谢谢

    如果您在运行
    docker build
    之前在主机上运行,您将拥有安装应用程序所需的所有gem文件的本地副本。然后,
    --local
    选项将使用本地目录,而不是尝试远程获取文件。您的Dockerfile部分看起来像

    COPY Gemfile Gemfile.lock .
    COPY vendor/cache vendor/cache
    RUN bundle install --frozen --local --system
    
    这避免了您尝试使用ssh密钥时出现的相当危险的舞蹈:拥有该映像的任何人都可以查看其
    docker历史记录
    ,或者只需运行容器,就可以轻松地取出您的ssh私钥

    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    
    COPY Gemfile Gemfile.lock .
    COPY vendor/cache vendor/cache
    RUN bundle install --frozen --local --system