I am new to docker and was trying to integrate docker with my rails app. I was following this doc
I was able to setup the services but I am facing a problem.
Whenever I add a Gem to my Gemfile I get error in docker-compose up
saying
sidekiq_1 | bundler: failed to load command: sidekiq (/usr/local/bundle/bin/sidekiq)
sidekiq_1 | /usr/local/bundle/gems/bundler-2.2.3/lib/bundler/resolver.rb:309:in `block in verify_gemfile_dependencies_are_found!': Could not find gem 'awesome_print' in any of the gem sources listed in your Gemfile. (Bundler::GemNotFound)
Dockerfile
FROM ruby:3.0.0-alpine3.12
ENV BUNDLER_VERSION=2.2.3
RUN apk add --update --no-cache
binutils-gold
build-base
curl py-pip
curl
file
g++
gcc
git
less
libstdc++
libffi-dev
libc-dev
linux-headers
libxml2-dev
libxslt-dev
libgcrypt-dev
make
netcat-openbsd
nodejs
openssl
pkgconfig
python3
tzdata
yarn
RUN gem install bundler -v 2.2.3
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle check || bundle install
COPY package.json yarn.lock ./
RUN yarn install --check-files
COPY . ./
ENTRYPOINT ["./entrypoints/docker-entrypoint.sh"]
docker-compose.yml
version: '3.6'
services:
app:
build:
context: .
dockerfile: Dockerfile
container_name: sna-main
depends_on:
- redis
ports:
- "3000:3000"
volumes:
- .:/app
- gem_cache:/usr/local/bundle/gems
- node_modules:/app/node_modules
environment:
RAILS_ENV: development
redis:
image: redis:5.0.7
sidekiq:
build:
context: .
dockerfile: Dockerfile
depends_on:
- app
- redis
volumes:
- .:/app
- gem_cache:/usr/local/bundle/gems
- node_modules:/app/node_modules
environment:
RAILS_ENV: development
entrypoint: ./entrypoints/sidekiq-entrypoint.sh
volumes:
gem_cache:
node_modules:
It would be great if someone can help me out to understand how to run bundle install every time there is a change in Gemfile.
From the doc I have understood that because we are caching the Gems so we need to remove the volume explicitly if we add/remove a new gem.
I did remove the volumes by running docker-compose down -v
.
It removed the volumes but still getting the same error.
2
Answers
I got it work by adding
bundle install
in my entrypoint file----------------./entrypoints/docker-entrypoint.sh-----------------
----------------./entrypoints/sidekiq-entrypoint.sh-----------------
There’s a chance that this is because docker-compose cached your images; you need to re-build with
docker-compose up --build
to reflect the image changes in docker-compose.