docker和bundler问题

时间:2015-09-29 22:36:25

标签: ruby-on-rails docker bundler docker-compose

我正在使用docker / docker-compose和bundler运行一些问题。构建我的图像后,我可以正确地运行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密钥挂载卷,因为有些宝石需要从私有存储库中提取。

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

1 个答案:

答案 0 :(得分:4)

您需要立即将此图片下载 。以下不起作用:

RUN rm /root/.ssh/id_rsa

您无法删除此类文件;它们仍然存在于先前的图层中,任何拥有图像的人都可以访问它们。目前,您正在发送您的秘密。

关于实际问题,我怀疑它只是与工作目录和路径有关。尝试将RUN bundle install移至WORKDIR指令之后。