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….

  • Running Appscale on Jelastic
  • docker-compose base version as build attribute
  • Docker error when uploading image
  • VSTS Docker Integration fails to install
  • Cython embed binary (docker): Failed to import the site module
  • docker run local script without host volumes
  • 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


  • Where are docker images stored by boot2docker?
  • How to use Dockerfile to link main container to a db container?
  • How to use Nginx to connect to my app in Docker image?
  • Service 'nginx' failed to build: … read-only file system
  • docker host rebooted automatically when running docker build/run
  • Managing mysql users in a Docker environment
  • 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.