【问题标题】:Error building docker image with Dockerfile使用 Dockerfile 构建 docker 映像时出错
【发布时间】:2018-04-23 21:27:24
【问题描述】:

我正在尝试使用Dockerfile 中的配置构建 docker 映像:

FROM ubuntu
MAINTAINER axiom88guru(axiom88guru@gmail.com)
Configuration for app below.
Run upgrades

RUN apt-get update
Install basic packages

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
Install Ruby

RUN apt-get -qq -y install ruby-full
RUN gem install bundler --no-ri --no-rdoc
RUN gem install foreman
Install rails-new-docker

WORKDIR /app
RUN git clone https://github.com/axiom88-guru/rails-docker.git /app
RUN bundle install --without development test
Run rails-new-docker

ENV SECRET_KEY_BASE dockerkeybase
ENV RAILS_ENV production
EXPOSE 5959
CMD foreman start -f Procfile

当我在 bash 中运行这些命令时,它们按预期工作,但在 docker build 期间却没有:

Removing intermediate container 344e99851852
Step 8/14 : WORKDIR /app
—> 3c204a395f23
Removing intermediate container 680b1841a3fc
Step 9/14 : RUN git clone https://github.com/axiom88-guru/rails-docker.git /app
—> Running in d7a9de9f6ab5
/bin/sh: 1: git: not found
The command ‘/bin/sh -c git clone https://github.com/axiom88-guru/rails-docker.git /app’ returned a non-zero code: 127

谁能帮我找出解决办法吗?

【问题讨论】:

  • 你需要安装git,它没有在基础ubuntu镜像中提供
  • 我使用的是 ubuntu16.0.4,它支持 git :)
  • docker run ubuntu:16.04 sh -c git 会给你同样的错误,因为它没有安装在提供的ubuntu 图像中。您必须 apt-get install git 才能正常工作。

标签: ruby-on-rails docker github dockerfile ubuntu-16.04


【解决方案1】:

需要安装 git,因为基本的 ubuntu 映像仅提供最小的已安装包集(这样做是为了保持映像大小较小)。

FROM ubuntu
MAINTAINER axiom88guru(axiom88guru@gmail.com)
# Configuration for app below.
# Run upgrades

RUN apt-get update
# Install basic packages

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs git
# Install Ruby

RUN apt-get -qq -y install ruby-full
RUN gem install bundler --no-ri --no-rdoc
RUN gem install foreman
# Install rails-new-docker

WORKDIR /app
RUN git clone https://github.com/axiom88-guru/rails-docker.git /app
RUN bundle install --without development test
# Run rails-new-docker

ENV SECRET_KEY_BASE dockerkeybase
ENV RAILS_ENV production
EXPOSE 5959
CMD foreman start -f Procfile

这个版本应该可以工作。我刚刚将git 添加到第一个apt-get install 步骤中。

【讨论】:

  • 这是一个不错的技巧。我什至不知道来自 docker 的 ubuntu 映像不提供 git。非常感谢,您节省了我的时间:)
猜你喜欢
  • 2020-10-17
  • 2018-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
  • 1970-01-01
  • 2017-02-11
  • 1970-01-01
相关资源
最近更新 更多