Rails docker - 捆绑自定义路径无法访问宝石

时间:2016-04-12 08:45:05

标签: ruby-on-rails docker bundler

我有一个Dockerfile,主要部分如下:

    FROM ruby:2.2.4

# Create user and group
RUN groupadd myapp --gid 6156 && \
    useradd --home /home/myapp --create-home --shell /bin/false --uid 6157 --gid 6156 myapp

# Create and switch to the repo dir
ENV REPO_DIR /home/myapp/repo
RUN mkdir $REPO_DIR
WORKDIR $REPO_DIR


# First install gems
ADD Gemfile      $REPO_DIR
ADD Gemfile.lock $REPO_DIR
RUN mkdir -p /var/bundle &&\
  chown -R myapp:myapp /var/bundle &&\
  mkdir $REPO_DIR/.bundle &&\
  chown -R myapp:myapp $REPO_DIR/.bundle
RUN su -c " cd $REPO_DIR && bundle install --deployment --path /var/bundle" -s /bin/bash -l myapp

 ...
CMD  ["rails","s", "-b", "0.0.0.0"]

主要部分是

  • 以客户myapp用户身份
  • 运行
  • bundle install --deployment--path /var/bundle参数

当我docker-compose up时,图像构建正确。但是,当我跑

docker-compose run --service-ports api /bin/bash

然后,

$ bundle check

说所有的宝石都丢失了..

$ bundle config 

Settings are listed in order of priority. The top value will be used.
silence_root_warning
Set via BUNDLE_SILENCE_ROOT_WARNING: "1"

app_config
Set via BUNDLE_APP_CONFIG: "/usr/local/bundle"

bin
Set via BUNDLE_BIN: "/usr/local/bundle/bin"

path
Set via BUNDLE_PATH: "/usr/local/bundle"

存在一些问题,因为在这种情况下BUNDLE_PATH应为/var/bundle

显然,bundle exec railsrails not found. Please install all missing gems

我应该怎样做才能从/var/bundle访问已安装的宝石?

Bundle install fails in Rails Docker container看起来很相似,但没有帮助。我所有的测试都在当地。

0 个答案:

没有答案