Setting up jenkins with docker and bundler

So i seem to be getting nowhere fast when trying to get bundler set up with jenkins using docker, setting up jenkins is fine, no problems there, but I can’t figure out how to get bundler accessible

FROM jenkins
USER root
RUN gpg --keyserver hkp:// --recv-keys D39DC0E3
RUN /bin/bash -l -c "curl -L | bash -s stable --ruby"
RUN /bin/bash -l -c "source /usr/local/rvm/scripts/rvm"
USER jenkins

A previous comment in another post has advised install bundler from the debian package, but not sure how i would do that or another option would be to add the GEM_PATH to the PATH variable….

  • How to use/link remote postgres db with django docker implementation
  • docker --storage-opt dm.basesize=40G does not work?
  • Docker containers can not start based on Dockerfile
  • unable to find user root: no matching entries in passwd file
  • Colocate docker containers using docker swarm
  • Docker-compose , anyway to specify a redis.conf file?
  • RUN /bin/bash -l -c 'export GEM_PATH=/usr/local/bundle' >> $PATH/.bashrc

    dont think that’s right at all

    The reason i need bundler is that in my post build script in jenkins i need to run bundle exec rubocop and bundle install

    Any help appreciated on this one as really quite stuck


  • How to configure priorities for Spark and OpenMPI to coexist on a cluster?
  • Docker workflow for automated builds on Github-Dockerhub
  • Docker OSX Unable to Access Container via IP Address
  • Dockerfile make error code 2
  • linux driver development: How does docker make sure app version matches kernel version?
  • How to get the clients external ip, im using Gcloud/kubernetes
  • 2 Solutions collect form web for “Setting up jenkins with docker and bundler”

    I’ve come up with this:

    $ cat Dockerfile 
    FROM jenkins
    USER root
    RUN apt-get update && apt-get install -y ruby bundler
    USER jenkins
    $ cat Gemfile
    source ""
    gem "hello-world"
    $ docker run -ti  -v $(pwd):/src $(docker build -q .) sh -c "cd /src ; bundle install --binstubs --path vendor/bundle ; ./bin/hello-world" 
    Using hello-world 1.2.0
    Using bundler 1.7.4
    Your bundle is complete!
    It was installed into ./vendor/bundle
    this is executable hello-world

    This works for this hello-world example. In your question you’re installing rvm. People often do this because rvm allows to install plenty of different ruby versions when your projects are using specific versions.

    Note: in your Dockerfile, the RUN /bin/bash -l -c "source /usr/local/rvm/scripts/rvm" is totally useless, as it sources the script that sets up the environment to use a specific ruby version at runtime (within the current shell). When the docker image is produced, variables set by running this script aren’t set in a container running this image.

    My answer to this was adding steps to install rvm also for ‘jenkins’ user almost in the end of the Dockerfile and then changing back to ‘root’

    USER jenkins
    RUN gpg --keyserver hkp:// --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
    RUN \curl -sSL | bash -s stable
    RUN /bin/sh -c export PATH="$PATH:/usr/local/rvm/bin" [[ -s "$HOME/.rvm/scripts/rvm" ]]
    RUN /bin/sh -c export PATH="$PATH:/usr/local/rvm/bin" -s "source '$HOME/.rvm/scripts/rvm'"
    RUN echo "source /usr/local/rvm/scripts/rvm" >> /home/jenkins/.profile
    USER root
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.