Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

docker - linux source command not working when building Dockerfile

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

Here is the Dockerfile:

FROM ubuntu:14.04
MAINTAINER example <[email protected]>

# 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

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

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 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...