Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when creating a Docker image for Ruby On Rails environment (from a Dockerfile)

I guess it's a environment problem. When I do it manually (without a Dockerfile) it works.

Here's my Dockerfile:

FROM ubuntu:14.04
RUN apt-get update
RUN apt-get upgrade --assume-yes
RUN apt-get install wget vim git --assume-yes
# install RVM
RUN apt-get install build-essential curl --assume-yes
RUN curl -L https://get.rvm.io | bash -s stable
RUN echo 'source /etc/profile.d/rvm.sh' >> ~/.bashrc
RUN /usr/local/rvm/bin/rvm-shell -c "rvm requirements"
# install Ruby
RUN /usr/local/rvm/bin/rvm-shell -c "rvm autolibs enable"
RUN /usr/local/rvm/bin/rvm-shell -c "rvm install 2.1.2"
# install Rails
RUN echo "gem: --no-rdoc --no-ri" >> ~/.gemrc
RUN gem install rails -v 4.1.5
# install nodeJS
RUN sudo apt-get install nodejs --assume-yes
EXPOSE 3000

Than I build with:

sudo docker build -t="james/rails" .

I get that error:

Step 11 : RUN gem install rails -v 4.1.5
 ---> Running in 44efc6b7c254
/bin/sh: 1: gem: not found
2014/09/04 18:33:52 The command [/bin/sh -c gem install rails -v 4.1.5] returned a non-zero code: 127
like image 297
James Avatar asked Sep 04 '14 16:09

James


People also ask

How do I run a docker app in Rails?

In your terminal, change your directory to the docker-rails directory and run the following command: >_ docker build -t rubyapp . To create a container from this image, run the command docker run -p 3000:3000 rubyapp . This creates a container and binds port 3000 of your host computer to port 3000 of the container.

What is Ruby docker?

2.2K. Ruby is a dynamic, reflective, object-oriented, general-purpose, open-source programming language. docker pull ruby.


2 Answers

Try RUN /bin/bash -l -c "gem install rails -v 4.1.5" instead of the line you've got in there. Does that change anything?

like image 113
Alex Lynham Avatar answered Sep 19 '22 12:09

Alex Lynham


With the help from Alex Lynham, here's a working Dockerfile:

FROM ubuntu:14.04

RUN apt-get update
RUN apt-get install wget vim git --assume-yes

# install RVM
RUN apt-get install build-essential curl --assume-yes
RUN curl -L https://get.rvm.io | bash -s stable
RUN echo 'source /etc/profile.d/rvm.sh' >> ~/.bashrc
RUN /usr/local/rvm/bin/rvm-shell -c "rvm requirements"

# install Ruby
RUN /bin/bash -l -c "rvm autolibs enable"
RUN /bin/bash -l -c "rvm install 2.1.2"

# install Rails
RUN echo "gem: --no-rdoc --no-ri" >> ~/.gemrc
RUN /bin/bash -l -c "gem install rails -v 4.1.5"

# install nodeJS
RUN sudo apt-get install nodejs --assume-yes

EXPOSE 3000
like image 32
James Avatar answered Sep 18 '22 12:09

James