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 the manager can get the data (or any update done in the container ) from the worker nodes in a docker swarm
  • Why has Docker volume run out of space?
  • Docker with Microsoft SQL Server and .net desktop application
  • Cassandra connection idling and timing out
  • Ansible cannot import docker-py even though it is installed
  • Docker mount directory access rights
  • 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


  • Docker cannot run
  • docker-compose volumes_from equivalent with version 3
  • Docker Minecraft Host
  • Restricting users in Docker group to not run privileged containers
  • How to bootstrap a docker container?
  • docker with device-mapper and luks
  • 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.