【发布时间】:2015-09-29 22:36:24
【问题描述】:
我在使用 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 密钥挂载一个卷,因为有一些 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
【问题讨论】:
标签: ruby-on-rails docker bundler docker-compose