我有一个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 rails
说rails not found. Please install all missing gems
。
我应该怎样做才能从/var/bundle
访问已安装的宝石?
Bundle install fails in Rails Docker container看起来很相似,但没有帮助。我所有的测试都在当地。