scenario1
So the problem I am facing like after building the docker images. If I am going inside the docker container and doing GEM_PATH=$GEM_HOME gem list it is not showing all the gems installed at the time of building the image. it is showing only a few gems.
scenario2
If I am not sourcing the RVM path inside the Dockerfile. Then If I am going inside the docker container and doing GEM_PATH=$GEM_HOME gem list then it is showing all the gems.
Can anyone please explain to me why this is happening and how I should install and source RVM? So I can see all the gems inside the container. Basically, I want the scenario1 should work. Thanks
Below is my Dockerfile
FROM ruby:2.6.5
RUN apt-get update -qq && apt-get install -y sudo && apt-get install -y build-essential && apt-get install -y apt-utils && apt-get install -y git
RUN gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB && \curl -sSL https://get.rvm.io | sudo bash -s stable --ruby && echo 'source /usr/local/rvm/scripts/rvm' >> /etc/bash.bashrc
RUN /bin/bash -l -c 'gem install bundler -v 1.17.3'
RUN /bin/bash -l -c 'gem install rails --version=5.2.4.1'
WORKDIR /app
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle config set path 'vendor/bundle'
COPY Gemfile Gemfile.lock ./
ARG SSH_KEY
# Make ssh dir
RUN mkdir /root/.ssh/
# Copy ssh
RUN echo "$SSH_KEY" > /root/.ssh/id_rsa && \
chmod 0600 /root/.ssh/id_rsa
RUN touch /root/.ssh/known_hosts
# Add bitbuckets key
RUN ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts
RUN bundle install
COPY . ./
EXPOSE 80:80
CMD rails s -p 80 -b '0.0.0.0' -e qa
TL;DR: don't use rvm\rbenv within a container
the whole thing when using containers, is to bundle\package all the dependencies inside a container. for instance, if you need ruby 2.9 then use a docker image which has ruby 2.9 installed rather than using rvm[rbenv](https://github.com/rbenv/rbenv).
since you are using bundler, i will advise you to add rails gem to it, and let bundler manage the dependencies.
i assume that you care about the directory where rubygems are being installed for caching propose, and i see that you instruct bundler exactly what is the rubygem home directory
RUN bundle config set path 'vendor/bundle'
I am building a website using bundle and im building it through docker containers. Apparently when i install ruby-bundler, its giving me bundler 1.15.1 instead of 1.16.4 and it throws a warning that my bundler is outdated. This is leading to some other issues with some files im trying to update.
Here is my Dockerfile:
FROM ubuntu:17.10
RUN apt-get update && apt-get install -y \
git \
gcc \
make \
ruby \
ruby-dev \
locales \
ruby-bundler \
zlib1g-dev \
curl
RUN gem install bundler
RUN rm -rf /var/lib/apt/lists/*
# Add support for UTF-8.
RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8
The line RUN gem install bundler is fixing the issue for me locally, but not on the docker image. So I ran which -a bundle and it gave me two directories: /usr/bin and /usr/local/bin. The new bundler seems to be installed on the local/bin and when i run bundle install it doesnt look for the local/bin therefore it throws me the warning.
What would be the best way to overcome this? Just keep in mind it has to be automated.
If I understood correctly you want only the newest version provided by gem install bundler
In that case all you need is to remove the ruby-bundler from the apt-get install remaining with this final Dockerfile
FROM ubuntu:17.10
RUN apt-get update && apt-get install -y \
git \
gcc \
make \
ruby \
ruby-dev \
locales \
zlib1g-dev \
curl
RUN gem install bundler
RUN rm -rf /var/lib/apt/lists/*
# Add support for UTF-8.
RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8
I am trying to install ruby on docker. I could install the 1.9 versions but it is not possible to install the latest version such as 2.2.0 and above. I am actually trying to set up calabash on docker. Have tried this. Whenever I try to install calabash-android in it getting the error
ERROR: Error installing calabash-android:
luffa requires Ruby version >= 2.0.
If you're starting FROM a different base Docker instance, you can simply RUN commands that install Ruby from your base instance's package management system. For example, this GitHub Gist shows how to use apt-get to install Ruby on a Ubuntu instance:
# Pull base image.
FROM dockerfile/ubuntu
# Install Ruby.
RUN \
apt-get update && \
apt-get install -y ruby
And this Gist shows a Dockerfile that's configured to install RVM and Ruby on a Ubuntu instance:
FROM ubuntu
RUN apt-get update
# basics
RUN apt-get install -y openssl
# install RVM, Ruby, and Bundler
RUN \curl -L https://get.rvm.io | bash -s stable
RUN /bin/bash -l -c "rvm requirements"
RUN /bin/bash -l -c "rvm install 2.0"
RUN /bin/bash -l -c "gem install bundler --no-ri --no-rdoc"
This makes ruby available for any future RUN command and not just bash:
FROM debian:stretch-slim
RUN \
apt-get update && apt-get install -y --no-install-recommends --no-install-suggests curl bzip2 build-essential libssl-dev libreadline-dev zlib1g-dev && \
rm -rf /var/lib/apt/lists/* && \
curl -L https://github.com/sstephenson/ruby-build/archive/v20180329.tar.gz | tar -zxvf - -C /tmp/ && \
cd /tmp/ruby-build-* && ./install.sh && cd / && \
ruby-build -v 2.5.1 /usr/local && rm -rfv /tmp/ruby-build-* && \
gem install bundler --no-rdoc --no-ri
You could start view a dockerfile starting with:
# 2016
FROM ruby:2.3.0
# 2020
# Import your ruby version
FROM ruby:2.7.1
# Install bundler gem
RUN gem install bundler
# Assign a work directory
WORKDIR /work
That would use the docker image ruby, with ruby already installed.
The 2020 version comes from "Ruby version management with docker" from Arjun Das, mentioned by ArMD in the comments.
Low reputation so I can't comment inline (all those years of lurking, sigh), but in case anyone else happens across this while searching for ways to install old ruby versions to docker, I found #grosser's answer very helpful - it worked where trying to install via RVM simply wouldn't, at least for me.
I would, however, recommend using the recommended approach for installing ruby-build - the following worked for me:
<prior steps>
RUN git clone https://github.com/rbenv/ruby-build.git && \
PREFIX=/usr/local ./ruby-build/install.sh && \
ruby-build -v 2.4.1 /usr/local && \
gem install bundler -v <VERSION HERE> --no-ri --no-rdoc && bundle install
<following steps>
Key point here is that this keeps you up to date with ruby-build instead of being hard-coded to the 2018-03-29 version as in a previous #grosser's comment.
If you want to use things like bundle install and don't use a base image with pre-installed devtools like Ubuntu, you need to install these packages:
RUN apt-get update && apt-get install -y ruby ruby-dev ruby-bundler build-essential
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
Thanks to #Jacob and #grosser, I've managed to set up mine in a similar, if a bit more unpacked way:
# Install Local ruby
RUN git clone https://github.com/rbenv/rbenv.git ~/.rbenv \
&& echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc \
&& echo 'eval "$(rbenv init -)"' >> ~/.bashrc
ENV HOME /home/jenkins # Change this dir as needed.
ENV PATH "$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"
ENV RUBY_VERSION 2.6.3
RUN mkdir -p "$(rbenv root)"/plugins \
&& git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
RUN rbenv install $RUBY_VERSION
RUN rbenv global $RUBY_VERSION && rbenv versions && ruby -v
# RUN curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash # Uncomment this to get rbenv to validate your setup.
I am attempting to create a docker image of a rails app using rvm (as non-root) and am running into permission errors:
Dockerfile:
FROM ubuntu
RUN apt-get update -q
RUN apt-get install -qy curl
RUN apt-get install -y libpq-dev
RUN apt-get install -y imagemagick --fix-missing
RUN apt-get install -y curl patch gawk g++ gcc make libc6-dev patch libreadline6-dev zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 autoconf libgdbm-dev libncurses5-dev automake libtool bison pkg-config libffi-dev
RUN useradd -ms /bin/bash app
USER app
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
RUN curl -sSL https://get.rvm.io | bash -s stable
RUN /bin/bash -c -l 'rvm install 2.2.1'
RUN /bin/bash -c -l 'rvm use 2.2.1'
RUN /bin/bash -l -c "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
RUN /bin/bash -c -l 'gem install bundler --no-ri --no-rdoc'
RUN /bin/bash -c -l 'mkdir /home/app/rails_app'
WORKDIR /home/app/rails_app
ADD Gemfile /home/app/rails_app/Gemfile
ADD Gemfile.lock /home/app/rails_app/Gemfile.lock
RUN /bin/bash -c -l 'bundle install'
ADD . /home/app/rails_app
EXPOSE 3000
CMD /bin/bash -c -l 'RAILS_ENV=production rails server -p 3000'
The image builds fine but when I run the container with docker run
I get the following error:
/home/app/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/server.rb:367:in `delete': Permission denied # unlink_internal - /home/app/rails_app/tmp/pids/server.pid (Errno::EACCES)
If I add:
USER root
RUN /bin/bash -c -l 'chmod -R 777 /home/app/rails_app/'
RUN /bin/bash -c -l 'chown -R app:app /home/app/rails_app/'
USER app
The container runs but the rails server did not start and there is nothing in the logs. Executing /bin/bash on the running container and trying to start the rails server ends in rails: command not found while logged in as app. Any Ideas?
Thanks
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
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?
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
You need to install rubygems before being able to use it.
RUN apt-get install rubygems
see also : Can I install gems with apt-get on Ubuntu?