捆绑商安装gem不坚持无花果/docker

我正在尝试使用fig和docker为现有的rails应用程序build立一个本地开发环境。

在构build过程中,我清楚地看到bundler安装应用程序的gem,但是当我尝试用fig up命令启动容器,甚至使用/ bin / bash命令重新打开容器时,gem是不可见的。

这是Dockerfile:

 FROM ubuntu:14.04 # REPOS RUN apt-get -qq update RUN apt-get install -y software-properties-common RUN add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe" RUN add-apt-repository -y ppa:chris-lea/node.js RUN apt-get -y update #INSTALL RUN apt-get install -y -q build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison pkg-config libpq-dev make wget unzip git vim nano nodejs gawk libgdbm-dev libffi-dev #RUBY RUN mkdir -p /download WORKDIR download RUN wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz RUN tar xvfz ruby-2.1.2.tar.gz WORKDIR /download/ruby-2.1.2 RUN ./configure RUN make RUN make install RUN gem update --system RUN gem install bundler RUN mkdir /rent WORKDIR /rent ADD Gemfile /rent/Gemfile ADD Gemfile.lock /rent/Gemfile.lock RUN bundle install --deployment 

这里是fig.yml文件:

 web: build: . command: bundle exec rails s -p 3000 volumes: - .:/rent ports: - "3000:3000" 

运行fig build清楚地显示了正在安装的应用程序的gem。 运行fig up失败的消息

bundler:找不到命令:rails

如果我运行fig run web /bin/bash和检查的内容

/local/lib/ruby/gems/2.1.0/gems

它只安装了bundler,rdoc,rake和其他一些软件。

如果我导航到应用程序的目录并运行bundle命令,它将安装应用程序的gem,我可以看到他们安装在上面的目录。 我甚至可以用rails server启动应用程序。

为什么不是在图像(容器?)中保存了捆绑的gem。

我从无花果网站上跑出铁轨,没有这个问题。

谢谢

看起来问题是由于使用bundle install--deployment标志导致的。

这个标志的主要作用是将gems部署到vendor / bundle /目录,而不是正常的gem位置。 我检查了gem,所以我不确定为什么ruby找不到它们。

无论如何,删除--deployment固定的问题。

如果您使用无花果和装入卷,我发现一个解决scheme,允许在开发中更新正在装载的文件(如Gemfile.lock,当你fig run web bundle install ),同时仍然保持容器caching行为。

看到这个完整的东西: https : //gist.github.com/fotinakis/04077671bec4edf77c08

这有些复杂,但基本上你总是安装bundler和gem作为非root用户:

 # Add 'web' user which will run the application. RUN adduser web --home /home/web --shell /bin/bash --disabled-password --gecos "" # Add directory where all application code will live and own it by the web user. RUN mkdir /app RUN chown -R web:web /app # Install gems separately here to take advantage of container caching of `bundle install`. # Also, ensure that gems are installed as the web user and not system-wide so that we can run # `fig web bundle install` and the web user will have permissions to update the shared Gemfile.lock. ADD Gemfile /app/ ADD Gemfile.lock /app/ RUN chown -R web:web /app USER web ENV HOME /home/web ENV PATH $PATH:/home/web/.gem/ruby/2.1.0/bin ENV GEM_HOME /home/web/.gem/ruby/2.1.0 ENV GEM_PATH $GEM_HOME RUN gem install --user-install bundler WORKDIR /app/ RUN bundle install USER root # Add the whole application source to the image and own it all by web:web. # Note: this is overwritten in development because fig mounts a shared volume at /app. ADD . /app/ RUN chown -R web:web /app 

现在运行这个工具,并更新你的本地Gemfile.lock:

 $ fig run web bundle install