Specifying the version of bundle - docker

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

Related

Permission denied when docker build

I know there are a lot of questions with similar title but none of them is similar to my issue. My problem is simple, I'm trying to install a few packages in my dockerfile using the command install_packages. This results in a permission denied error stating /bin/sh: 1: install_packages: Permission denied
I've tried adding USER 0 and USER root but none of them worked. Below is my Dockerfile. What am I doing wrong?. Also saw a similar issue in github but the solution provided there didn't work for me.
Similar Issue: https://github.com/bitnami/bitnami-docker-wordpress/issues/230
Dockerfile: (Errors out in the sixth command)
FROM docker.io/bitnami/minideb:buster
LABEL maintainer "Bitnami <containers#bitnami.com>"
USER root
ENV HOME="/" \
OS_ARCH="amd64" \
OS_FLAVOUR="debian-10" \
OS_NAME="linux"
COPY prebuildfs /
# Install required system packages and dependencies
RUN install_packages ca-certificates curl ghostscript gzip imagemagick libc6 libgcc1 libgmp-dev libjemalloc-dev libncurses5-dev libncurses6 libreadline-dev libreadline7 libssl1.1 libstdc++6 libtinfo6 libxml2-dev libxslt1-dev procps tar zlib1g zlib1g-dev
RUN . /opt/bitnami/scripts/libcomponent.sh && component_unpack "ruby" "2.6.6-0" --checksum ecadce77e40822926c69f76cc11437954dd068793548c3f0a21007f9c4fafed3
RUN . /opt/bitnami/scripts/libcomponent.sh && component_unpack "gosu" "1.12.0-0" --checksum 582d501eeb6b338a24f417fededbf14295903d6be55c52d66c52e616c81bcd8c
RUN . /opt/bitnami/scripts/libcomponent.sh && component_unpack "fluentd" "1.10.4-0" --checksum 1428d81be002b7124db38326c73ebe9980e5b3c94a15e3054cdbdff9f8aa3979
RUN apt-get update && apt-get upgrade -y && \
apt-get install build-essential -y && \
rm -r /var/lib/apt/lists /var/cache/apt/archives
COPY rootfs /
RUN /opt/bitnami/scripts/fluentd/postunpack.sh
ENV BITNAMI_APP_NAME="fluentd" \
BITNAMI_IMAGE_VERSION="1.10.4-debian-10-r1" \
GEM_HOME="/opt/bitnami/fluentd" \
PATH="/opt/bitnami/ruby/bin:/opt/bitnami/common/bin:/opt/bitnami/fluentd/bin:$PATH"
#GEM Installation
WORKDIR /opt/bitnami/fluentd
RUN gem install jwk-tool
RUN fluent-gem install 'fluent-plugin-azure-storage-append-blob'
#RUN fluent-gem install 'fluent-plugin-encrypt'
RUN gem install fluent-plugin-jwt-filter && \
gem install json -v "~> 1.8" && \
gem install fluent-plugin-kubernetes && \
gem install fluent-plugin-kubernetes_metadata_filter && \
gem uninstall tzinfo -v 2.0.2
#RUN jwk_tool -g -k key
COPY ./key.pub /opt/bitnami/fluentd/key.pub
EXPOSE 24224 5140
WORKDIR /opt/bitnami/fluentd
#USER 1001
ENTRYPOINT [ "/opt/bitnami/scripts/fluentd/entrypoint.sh" ]
CMD [ "/opt/bitnami/scripts/fluentd/run.sh" ]
The "install_packages" file within the user path directory might not be set as executable by default. You can try making it executable "chmod +x /usr/sbin/install_packages" and try again. It worked for me.

Unable to use sudo commands within Docker, "bash: sudo: command not found" is displayed

I have installed TensorFlow using the following command
docker run -it b.gcr.io/tensorflow/tensorflow:latest-devel
and I need to set up TensorFlow Serving on a windows machine. I followed the instructions and while running the below-mentioned sudo command while installing TensorFlow Serving dependencies:
sudo apt-get update && sudo apt-get install -y \
build-essential \
curl \
git \
libfreetype6-dev \
libpng12-dev \
libzmq3-dev \
pkg-config \
python-dev \
python-numpy \
python-pip \
software-properties-common \
swig \
zip \
zlib1g-dev
The following error is displayed:
bash: sudo: command not found
docker comes along with root it doesnt require sudo.
BTW if you want sudo in docker if you want to install sudo,
try this,
apt-get update && \
apt-get -y install sudo
now you can use sudo along with your command in docker...
Docker images typically do not have sudo, you are already running as root by default. Try
apt-get update && apt-get install -y build-essential curl git libfreetype6-dev libpng12-dev libzmq3-dev pkg-config python-dev python-numpy python-pip software-properties-common swig zip zlib1g-d
If you wish to not run as root, see the Docker documentation on the User command.
We don't want to weaken the security of the container by installing sudo in it. But we also don't want to change existing scripts that work on normal machines just so that they work in docker, which doesn't need the sudo.
Instead, we can define a dummy bash script to replace sudo, which just executes the arguments without elevating permissions, and is only defined inside the docker image.
Add this to your Dockerfile:
# Make sudo dummy replacement, so we don't weaken docker security
RUN echo "#!/bin/bash\n\$#" > /usr/bin/sudo
RUN chmod +x /usr/bin/sudo

How to install Ruby on docker?

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.

How Can I install `passenger-install-nginx-module` via Dockerfile

How Can I install passenger-install-nginx-module via Dockerfile?
FROM ubuntu:14.04
MAINTAINER hgkim
RUN apt-get update \
&& apt-get install -y curl build-essential libpq-dev advancecomp gcc libpcre3 \
libpcre3-dev zlib1g zlib1g-dev libssl-dev gifsicle jhead \
jpegoptim libjpeg-progs optipng pngquant libzmq-dev libevent-dev python-dev \
python-virtualenv python libcurl4-openssl-dev \
&& virtualenv circus && /circus/bin/pip install circus-web==0.5 \
&& ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime \
&& useradd -d /home/newbie -m -s /bin/bash newbie \
&& usermod -aG root newbie \
&& echo 'ALL ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
&& curl -L -O http://sourceforge.net/projects/pmt/files/pngcrush/1.7.81/pngcrush-1.7.81.tar.gz \
&& tar xvzf pngcrush* \
&& cd pngcrush* \
&& make \
&& mv pngcrush /usr/local/bin/ \
&& cd / && curl -L https://github.com/kelseyhightower/confd/releases/download/v0.6.3/confd-0.6.3-linux-amd64 -o confd \
&& mv confd /usr/local/bin/confd && chmod +x /usr/local/bin/confd
USER newbie
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3 \
&& \curl -sSL https://get.rvm.io | bash -s stable \
&& /bin/bash -l -c "rvm install 2.1.0" \
&& /bin/bash -l -c "rvm use 2.1.0" \
&& echo "gem: --no-ri --no-rdoc" > /home/newbie/.gemrc
ENV PATH /home/newbie/.rvm/bin:/home/newbie/.rvm/gems/ruby-2.1.0/bin:/home/newbie/.rvm/gems/ruby-2.1.0#global/bin:/home/newbie/.rvm/rubies/ruby-2.1.0/bin:$PATH
RUN gem install passenger -v 4.0.55 \
&& rvmsudo passenger-install-nginx-module \
--auto --prefix=/usr/local/nginx --auto-download --languages ruby
CMD bash
Above is my dockerfile.
I just want to setup passenger-nginx-module...
But I got error in last RUN instruction in Dockerfile
RUN gem install passenger -v 4.0.55 \
&& rvmsudo passenger-install-nginx-module \
--auto --prefix=/usr/local/nginx --auto-download --languages ruby
First, install passenger,
Second, try to install nginx-module via rvmsudo passenger-install-nginx-module command.
But docker response this error
error:
Unable to autodetect the currently active RVM gem set name. This could happen if you ran this program using 'sudo' instead of 'rvmsudo'. When using RVM, you're always supposed to use 'rvmsudo' instead of 'sudo!'.
Please try rerunning this program using 'rvmsudo'. If that doesn't help, please contact this program's author for support.
Although I just tried to command rvmsudo...
What should I do?
try replace RUN passenger-install-nginx-module by
RUN /bin/bash -l -c 'passenger-install-nginx-module --auto-download --auto --prefix=/opt/nginx'
I'm sure there is a way to automate the config/build process -- but why? You know that the passenger-install-nginx-module downloads and compiles nginx from source right?
Why not just add the passenger apt repository and install it via apt-get? So much easier.
Passenger Debian Install Guide
What user2105103 said. You could also just use passenger-docker.
Try this
RUN passenger-install-nginx-module --auto-download --auto --prefix=/opt/nginx

How to check ruby version inside docker container

I have build the docker container by creating below docker file
# Select ubuntu as the base image
FROM ubuntu
# Install nginx, nodejs and curl
RUN apt-get update -q
RUN apt-get install -qy nginx
RUN apt-get install -qy curl
RUN apt-get install -qy nodejs
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
# Install rvm, ruby, bundler
RUN curl -sSL https://get.rvm.io | bash -s stable
RUN /bin/bash -l -c "rvm requirements"
RUN /bin/bash -l -c "rvm install 2.1.0"
RUN /bin/bash -l -c "gem install bundler --no-ri --no-rdoc"
# Add configuration files in repository to filesystem
ADD config/container/nginx-sites.conf /etc/nginx/sites-enabled/default
ADD config/container/start-server.sh /usr/bin/start-server
RUN chmod +x /usr/bin/start-server
# Add rails project to project directory
ADD ./ /rails
# set WORKDIR
WORKDIR /rails
# bundle install
RUN /bin/bash -l -c "bundle install"
# Publish port 80
EXPOSE 80
# Startup commands
ENTRYPOINT /usr/bin/start-server
When i go inside the container and give the command ruby -v it throws bash: ruby: command not found
Could any one help me in doing this
I've spent a bit of time messing with RVM, Ruby and Docker recently. This answer might not be what you're looking for, but it needs to be said anyway: if you don't absolutely need RVM, then don't use it in your docker file. You've already noticed one downside: having to pre-empt your commands with /bin/bash -lc. You'll run into another downside if you ever want to have a non-root user run a ruby program in your Docker container. Also, your problem is most likely related to Docker not loading .bashrc or .bash_profile (I forgot which one RVM modifies) when you run a bash shell.
Instead use this to compile Ruby from source:
RUN apt-get update
RUN apt-get install -yq build-essential openssl libreadline6 libreadline6-dev curl git-core \
zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev \
autoconf libc6-dev ncurses-dev automake libtool bison subversion libmysqlclient-dev
ADD http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz /tmp/
RUN cd /tmp && tar -xzf /tmp/ruby-2.1.2.tar.gz
RUN cd /tmp/ruby-2.1.2/ && ./configure --disable-install-doc && make && make install
RUN rm -rf /tmp/*
ADD http://production.cf.rubygems.org/rubygems/rubygems-2.4.1.tgz /tmp/
RUN cd /tmp && tar -xzf /tmp/rubygems-2.4.1.tgz
RUN cd /tmp/rubygems-2.4.1 && ruby setup.rb
RUN rm -rf /tmp/*
RUN echo "gem: --no-ri --no-rdoc" > ~/.gemrc
RUN gem install bundler --no-rdoc --no-ri
You are not setting the default ruby after installing RVM. Trying setting the default ruby after installing it.
RUN /bin/bash -l -c "rvm install 2.1.0"
RUN /bin/bash -l -c "rvm use 2.1.0 --default"

Resources