Bundler locks in docker + can't install gems (Solved- docker CMD vs ENTRYPOINT)

Update: I’ve narrowed the [or a?] problem down to the line - groupy-gemcache:/usr/local/bundle in my services: app: volumes dictionary. If I remove it, the container runs fine [i think] but presumably i lose my local gem cacheing.

tldr: After running docker-compose build, things seem ok, but I cannot run any gem or bundle inside my running docker container if I add something to my gemfile. for example, after docker-compose build && docker-compose run app bash:

  • What's the best approach to schedule tasks across docker cluster?
  • Assetss from wwwroot cannot be found on Docker Image
  • Can't kill processes (originating in a docker container)
  • Trying to push an image to the docker registry
  • Backup of Docker image
  • How to create docker image from jenkins running on docker
  • root@2ea58aff612e:/src# bundle check
    The Gemfile's dependencies are satisfied
    root@2ea58aff612e:/src# echo 'gem "hello-world"' >> Gemfile
    root@2ea58aff612e:/src# bundle
    Could not find gem 'hello-world' in any of the gem sources listed in your Gemfile.
    Run `bundle install` to install missing gems.
    root@2ea58aff612e:/src# bundle install
    Could not find gem 'hello-world' in any of the gem sources listed in your Gemfile.
    Run `bundle install` to install missing gems.
    root@2ea58aff612e:/src# gem
    Could not find gem 'hello-world' in any of the gem sources listed in your Gemfile.
    Run `bundle install` to install missing gems.
    root@2ea58aff612e:/src# gem env
    Could not find gem 'hello-world' in any of the gem sources listed in your Gemfile.
    Run `bundle install` to install missing gems.
    

    I’m still pretty novice with docker, but i’ve been trying to configure a perfect dockerfile that can build, cache gems and update while still committing its Gemfile.lock to git [maybe this isn’t actually perfect and I’m open to suggestions there]. In my use case, I’m using a docker compose file with images for a rails app and sidekiq worker as well as postgres and redis images- very simliar to the setups described here and here.

    My Dockerfile [some things commented out that I cobbled from the tutorials above:

        FROM ruby:2.3
        ENTRYPOINT ["bundle", "exec"]
        ARG bundle_path
        # throw errors if Gemfile has been modified since Gemfile.lock
        # RUN bundle config --global frozen 1
        ENV INSTALL_PATH /src
        RUN mkdir -p $INSTALL_PATH
        WORKDIR $INSTALL_PATH
    
    
    
        # Install dependencies:
        # - build-essential: To ensure certain gems can be compiled
        # - nodejs: Compile assets
        # - npm: Install node modules
        # - libpq-dev: Communicate with postgres through the postgres gem
        # - postgresql-client-9.4: In case you want to talk directly to postgres
        RUN apt-get update && apt-get install -qq -y build-essential nodejs npm libpq-dev postgresql-client-9.4 --fix-missing --no-install-recommends && \
        rm -rf /var/lib/apt/lists/*
    
        COPY app/Gemfile app/Gemfile.lock ./
    
        # Bundle and then save the updated Gemfile.lock in our volume since it will be clobbered in the next step
        RUN echo $bundle_path && bundle install --path=$bundle_path && \
        cp Gemfile.lock $bundle_path
    
        # ./app contains the rails app on host
        COPY app .
    
        # Unclobber the updated gemfile.lock
        RUN mv $bundle_path/Gemfile.lock ./
    
        CMD ["./script/start.sh"]
    

    docker-compose.yml:

    version: '2'
    volumes:
      groupy-redis:
      groupy-postgres:
      groupy-gemcache:
    
    services:
      app:
        build: 
          args:
            bundle_path: /usr/local/bundle
          context: .
          dockerfile: Dockerfile
        command: "./script/start.sh"
        links:
          - postgres
          - redis
        volumes:
          - ./app:/src
          - groupy-gemcache:/usr/local/bundle
        ports:
          - '3000:3000'
        env_file:
          - .docker.env
        stdin_open: true
        tty: true
    

  • Install Gitlab with disabled sign up
  • Install Docker in container for use by GitLab CI build
  • docker on windows not working
  • App container to cassandra node - one to one or?
  • Sensu-Client inside Docker container
  • docker-compose with MongoDb and volumes - doesn't seem to be mounted
  • One Solution collect form web for “Bundler locks in docker + can't install gems (Solved- docker CMD vs ENTRYPOINT)”

    Wow, I figured it out. The problem was coming from my ENTRYPOINT dockerfile command, as explained at the end of this article on CMD vs ENTRYPOINT.

    I believe the result of ENTRYPOINT ["bundle", "exec"] with CMD ["./script/start.sh"] OR docker-compose run app bash was to run a command like bundle exec 'bash'. I confirmed this by removing the entrypoint from the dockerfile, entering the shell as above and manually running bundle exec 'bash' and sure enough i landed in a subshell where I couldn’t run any bundle or gem commands- had to exit twice to leave.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.