LoginSignup
47
23

More than 5 years have passed since last update.

dockerでBundler::GemNotFoundが出るときの対処法

Posted at

環境

  • windows 10
  • WSL(Windows Subsystem for Linux)
  • Docker Toolbox

以下のような画像投稿アプリを勉強がてら作ったことあるんですが、Sinatraのバージョンが2.0.1で古いまま放置されていました。これを2.0.3にアップデートしようとした時にハマったのでメモがてら投稿です
GitHub - koyo-miyamura/latestgram

Dockerfile

FROM ruby:2.5.1

WORKDIR /app

ADD Gemfile /app/Gemfile
ADD Gemfile.lock /app/Gemfile.lock

RUN bundle install

EXPOSE 4567
docker-compose
version: "3"

services:
  web:
    build: . 
    volumes: 
      - .:/app
    ports: 
      - "4567:4567"
    depends_on:
      - db
    command: bundle exec ruby myapp.rb -o 0.0.0.0
    environment:
      - "TZ=Asia/Tokyo"

  nginx:
    image: nginx:latest
    volumes: 
      - ./conf/nginx.conf:/etc/nginx/nginx.conf
      - ./public:/var/www/html
    ports:
      - "8080:8080"
    depends_on:
      - web

  db:
    build: ./sql
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: "true"
      MYSQL_DATABASE: "latestgram"
      MYSQL_USER: "root"
      TZ: "Asia/Tokyo"
    volumes:
      - ./sql:/docker-entrypoint-initdb.d
    ports:
      - "3306:3306"

エラー内容

Gemfileを書き換えて以下のコマンドを実行

sudo bundle install
docker-compose up

すると以下のエラーが発生しました

/usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.1/lib/bundler/spec_set.rb:88:in `block in materialize': 
Could not find rack-protection-2.0.3 in any of the sources (Bundler::GemNotFound)

これ、よ~く考えると当たり前なんですが、聡明な皆さんはおわかりいただけたでしょうか・・・?(心霊特番風)

・・・
・・・
・・・

そうだね docker-compose build してないね!(パッション屋良風)

Dockerfileをbuildする段階でbundle installされているので、そりゃGemNotFoundなりますわ・・・。

結論

Gemfileを更新したらdocker-compose upする必要があるか確かめよう!(そもそもDockerfileでbundle installしない構成もありそうですが)

47
23
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
47
23