在Ruby Docker映像中安装Bundler失败

时间:2019-01-31 20:18:32

标签: docker docker-compose dockerfile

我有一个很老的项目我给的支持。我使用泊坞窗,使我的构建和一切工作,直到这最后一次尝试。

这是我的Dockerfile:

FROM ruby:2.1

# Install apt based dependencies required to run Rails as 
# well as RubyGems. As the Ruby image itself is based on a 
# Debian image, we use apt-get to install those.
RUN apt-get update && apt-get install -y \ 
    git \
    ghostscript \
    libgs-dev \
    build-essential \ 
    libmysqlclient-dev \
    locales \
    nodejs

# Use en_US.UTF-8 as our locale
RUN locale-gen en_US.UTF-8 
ENV LANG en_US.UTF-8 
ENV LANGUAGE en_US:en 
ENV LC_ALL en_US.UTF-8

# Configure the main working directory. This is the base 
# directory used in any further RUN, COPY, and ENTRYPOINT 
# commands.
RUN mkdir -p /app 
WORKDIR /app

# Copy the Gemfile as well as the Gemfile.lock and install 
# the RubyGems. This is a separate step so the dependencies 
# will be cached unless changes to one of those two files 
# are made.
COPY Gemfile Gemfile.lock ./ 
COPY vendor/oohlalog_gem ./vendor/oohlalog_gem
RUN gem install bundler && bundle install

# Copy the main application.
COPY . ./

# Expose port 3000 to the Docker host, so we can access it 
# from the outside.
EXPOSE 3000

# Configure an entry point, so we don't need to specify 
# "bundle exec" for each of our commands.
ENTRYPOINT ["bundle", "exec"]

# The main command to run when the container starts. Also 
# tell the Rails dev server to bind to all interfaces by 
# default.
CMD ["rails", "server", "-b", "0.0.0.0"]

当我尝试运行时:

docker build . -t my_image

我得到:

  

步骤11:运行gem install bundler && bundle install
  --->在7f8e7442b423中运行错误:安装捆绑器时出错:
  捆绑需要Ruby版本> = 2.3.0。

我不知道该如何解决。

2 个答案:

答案 0 :(得分:2)

这是2019年1月3日发布的新Bundler版本2.0.0的结果。根据GitHub issue,这是理想的行为。

由于这是一个旧项目,不再维护,因此最好的选择是使用旧的捆绑软件。

您可以从Dockerfile中修改该行:

RUN gem install bundler && bundle install

到以下:

RUN gem install bundler -v '$OLD_BUNDLER_VERSION' && bundle install

应将$ OLD_BUNDLER_VERSION设置为上一个已知的工作版本,即1.16.1

答案 1 :(得分:0)

尝试以较新版本的红宝石图像作为基础。您使用的是2.1(FROM ruby:2.1,但是您需要ruby版本2.3.0