问题与docker和捆绑

我正在用docker / docker-compose和bundler运行一些问题。 在构build映像后,我可以正确运行rails server ,但是,当我尝试使用rails console运行控制台时,我总是得到:

 Could not find i18n-0.7.0 in any of the sources Run `bundle install` to install missing gems. 

如果我尝试在容器中运行bundle install没有问题,所有似乎都正确安装。

docker-compose run web bundle install

 ... Using spring 1.3.6 Using therubyracer 0.12.2 Using turbolinks 2.5.3 Using uglifier 2.7.2 Using web-console 2.2.1 Updating files in vendor/cache Bundle complete! 24 Gemfile dependencies, 119 gems now installed. Bundled gems are installed into /usr/local/bundle. 

docker-compose.yml如下所示:

 db: image: postgres web: build: . command: rails s -p 3000 -b 0.0.0.0 ports: - "3000:3000" volumes: - .:/app - ./github_rsa:/root/.ssh/id_rsa links: - db 

我需要使用ssh密钥装入卷,因为有些gem需要从私有存储库中取出。

我的Dockerfile看起来像这样:

 FROM ruby:2.2.0 RUN apt-get update -qq && apt-get install -y build-essential \ libpq-dev \ libxml2-dev libxslt1-dev \ nodejs ENV HOME /root ENV APP_HOME /app RUN mkdir $APP_HOME RUN mkdir $APP_HOME/tmp RUN mkdir $APP_HOME/log # Copy the Gemfile and Gemfile.lock into the image. # Temporarily set the working directory to where they are. WORKDIR /tmp ADD Gemfile Gemfile ADD Gemfile.lock Gemfile.lock # Copy the github key for pulling gems COPY github_rsa /root/.ssh/id_rsa RUN \ chown -R root:root /root/.ssh && \ chmod 700 $HOME/.ssh && \ chmod 600 $HOME/.ssh/id_rsa RUN echo "Host github.com\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config # Start ssh agent and add keys RUN eval "$(ssh-agent)" && \ ssh-add && \ ssh-add -l # Install bundler RUN gem install bundler -v '~> 1.10' # Install ruby dependencies RUN bundle install # Remove the ssh key now, we don't want to ship secrets on our images RUN rm /root/.ssh/id_rsa # Add app to container ADD . $APP_HOME # Add container working directory WORKDIR $APP_HOME # Expose puma port EXPOSE 3000 

你需要立即拍下这张照片。 以下不起作用:

 RUN rm /root/.ssh/id_rsa 

你不能删除这样的文件; 他们仍然存在于以前的层面,任何有形象的人都可以访问。 目前,你正在运送你的秘密。

关于实际问题,我怀疑这只是工作目录和path。 尝试将RUN bundle installWORKDIR指令之后。