构建Dockerfile时linux源命令不起作用 [英] linux source command not working when building Dockerfile

查看:101
本文介绍了构建Dockerfile时linux源命令不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个定义Ruby on Rails堆栈的Dockerfile。

I have a Dockerfile that defines a Ruby on Rails stack.

这里是Dockerfile:

Here is the Dockerfile:

FROM ubuntu:14.04
MAINTAINER example <examplen@example.com>

# Update
RUN apt-get update

# Install Ruby and Rails dependencies
RUN apt-get install -y \
ruby \
ruby-dev \
build-essential \
libxml2-dev \
libxslt1-dev \
zlib1g-dev \
libsqlite3-dev \
nodejs \
curl

RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

RUN curl -sSL https://get.rvm.io | bash -s stable --rails

RUN /bin/bash -c "source /usr/local/rvm/scripts/rvm"

# Install Rails
RUN gem install rails

# Create a new Rails app under /src/my-app
RUN mkdir -p /src/new-app

RUN rails new /src/new-app

WORKDIR /src/my-app

# Default command is to run a rails server on port 3000
CMD ["rails", "server", "--binding", "0.0.0.0", "--port" ,"3000"]

EXPOSE 3000

当我执行命令 docker build -t anotherapp / my-rails-app。我得到以下信息错误:

When I execute the command docker build -t anotherapp/my-rails-app . I get the following error:


删除中间容器3f8060cdc6f5

步骤8:运行gem install rails

- ->在8c1793414e63中运行

错误:安装rails时出错:

activesupport需要Ruby版本> = 2.2.2。

命令'/ bin / sh -c gem install rails返回了非零代码:1

Removing intermediate container 3f8060cdc6f5
Step 8 : RUN gem install rails
---> Running in 8c1793414e63
ERROR: Error installing rails:
activesupport requires Ruby version >= 2.2.2.
The command '/bin/sh -c gem install rails' returned a non-zero code: 1

It l看起来像命令 source / usr / local / rvm / scripts / rvm 在构建期间不起作用。

It looks like the command source /usr/local/rvm/scripts/rvm isn't working during the build.

我不确定为什么会这样。

I'm not sure exactly why this is happening.

推荐答案

来自 docker构建器参考,每个RUN命令均独立运行。因此,执行 RUN源/ usr / local / rvm / scripts / rvm 对下一个RUN命令没有任何影响。

From the docker builder reference, each RUN command is run independently. So doing RUN source /usr/local/rvm/scripts/rvm does not have any effect on the next RUN command.

尝试如下更改需要给定源文件的操作

Try changing the operations which require the given source file as follows

  RUN /bin/bash -c "source /usr/local/rvm/scripts/rvm ; gem install rails"

这篇关于构建Dockerfile时linux源命令不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆