こんにちは!kossyです!
今回はアプリ開発環境に開発途中でdockerを用いた環境構築を行った際に軽くハマったことをブログに残してみたいと思います。
環境
Ruby 2.6.8
Rails 6.0.4.1
Docker-Compose 1.27.0
docker-compose build が通らない
以下のようなdockerfileおよびdocker-compose.ymlを書きました。
FROM ruby:2.6 ENV LANG C.UTF-8 RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs vim graphviz RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock RUN bundle install COPY . /app
version: '3' services: db: image: postgres:13.4 environment: POSTGRES_USER: root POSTGRES_PASSWORD: password ports: - "2345:2345" volumes: - ./tmp/db:/var/lib/postgresql/data web: build: . command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" volumes: - .:/app - gem_data:/usr/local/bundle ports: - 3000:3000 depends_on: - db tty: true stdin_open: true volumes: gem_data:
コンソールで docker-compose build を実行すると、以下のエラーログが出力されました。
/usr/local/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.1.4) required by your /app/Gemfile.lock. (Gem::GemNotFoundException) To update to the latest version installed on your system, run `bundle update --bundler`. To install the missing version, run `gem install bundler:2.1.4` from /usr/local/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path' from /usr/local/bin/bundle:23:in `<main>'
どうやらGemfile.lockのbundlerのバージョンが見つからないと言われているようだったので、Gemfile.lockを一度空にし、再度 docker-compose build を実行したところ、buildが通りました。
皆さんも開発環境に途中からdockerを導入する場合はお気をつけください。