ruby-on-rails – 在docker中没有安装私有宝石

我正在尝试使用docker运行rails应用程序.很少有宝石由 github的ssh url安装,如下所示:

Gemfile

gem 'swagger-docs',:git => 'git@github.com:xyz/swagger-docs.git',:branch => 'my_branch'

我在docker中添加了键,它能够克隆所需的repo并从git安装gem.

Dockerfile

RUN mkdir -p /root/.ssh
copY ./id_rsa /root/.ssh/id_rsa

RUN chmod 700 /root/.ssh/id_rsa

RUN ssh-keygen -f /root/.ssh/id_rsa -y > /root/.ssh/id_rsa.pub

RUN ssh-keyscan github.com >> /root/.ssh/kNown_hosts

当我构建它(包括捆绑安装)时,一切顺利,图像成功构建.但是当我运行docker-compose时,会出现以下错误

/usr/local/bundle/gems/bundler-1.9.2/lib/bundler/source/git/git_proxy.rb:155:in `allowed_in_path': The git source git@github.com:xyz/swagger-docs.git is not yet checked out. Please run `bundle install` before trying to start your application (Bundler::GitError)

解决方法

尝试在Gemfile中用https替换git,即

gem 'swagger-docs',git: 'https://github.com:xyz/swagger-docs.git',branch: 'my_branch'

…或者在运行bundle install之前将其添加到Dockerfile中:

RUN git config --global url."https://".insteadOf git://

如果没有任何作用,那么只需运行两次捆绑安装,即

...
  RUN gem install bundler && bundle install

  CMD bundle install && rails s -p 3000 -b 0.0.0.0

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...