前提
いろいろな参考サイトを閲覧して、Dockerfile docker-compose.yml Gemfileを生成。
実行コマンド
$ docker-compose run web bundle exec rails new . --force --database=mysql --skip-bundle
$ docker-compose build
$ docker-compose up -d
試行錯誤したこと
- キャッシュが貯まるという記事を得て実行 docker-compose build --no-cache にてコマンドを実行してみた
- このコマンドを実行したら良いという情報を得て実行RUN gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/' -- --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib
- mysql-devel が必要ということで、RUN apt-get 時に mysql-develを実行
結果エラーになりました。「E: Unable to locate package mysql-devel」
ファイル内容
Dockerfile docker-compose.yml Gemfileはそれぞれ下記に記載しております。
Dockerfile
1FROM ruby:2.6.5 2ENV LANG C.UTF-8 3 4RUN apt-get update -qq && apt-get install -y \ 5 build-essential \ 6 nodejs \ 7 mysql-devel \ 8 && rm -rf /var/lib/apt/lists/* 9 10RUN gem install bundler 11 12WORKDIR /tmp 13ADD Gemfile Gemfile 14ADD Gemfile.lock Gemfile.lock 15RUN bundle update 16RUN bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include" 17RUN bundle install --path=vendor/bundle 18RUN gem update 19 20ENV APP_HOME /myapp 21RUN mkdir -p $APP_HOME 22WORKDIR $APP_HOME 23ADD . $APP_HOME
docker
1version: '3' 2 3services: 4 web: 5 build: . 6 ports: 7 - "3000:3000" 8 command: bundle exec rails s -p 3000 -b '0.0.0.0' 9 volumes: 10 - .:/myapp 11 - bundle:/usr/local/bundle 12 depends_on: 13 - db 14 db: 15 image: mysql:5.7 16 environment: 17 MYSQL_ROOT_PASSWORD: password 18 ports: 19 - '3306:3306' 20 volumes: 21 - mysql_data:/var/lib/mysql 22volumes: 23 bundle: 24 mysql_data:
Gemfile
1source 'https://rubygems.org' 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby '2.6.5' 5 6# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 7gem 'rails', '~> 6.0.0' 8# Use mysql as the database for Active Record 9gem 'mysql2', '>= 0.4.4' 10# Use Puma as the app server 11gem 'puma', '~> 3.11' 12# Use SCSS for stylesheets 13gem 'sass-rails', '~> 5' 14# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker 15gem 'webpacker', '~> 4.0' 16# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 17gem 'turbolinks', '~> 5' 18# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 19gem 'jbuilder', '~> 2.7' 20# Use Redis adapter to run Action Cable in production 21# gem 'redis', '~> 4.0' 22# Use Active Model has_secure_password 23# gem 'bcrypt', '~> 3.1.7' 24 25# Use Active Storage variant 26# gem 'image_processing', '~> 1.2' 27 28# Reduces boot times through caching; required in config/boot.rb 29gem 'bootsnap', '>= 1.4.2', require: false 30 31group :development, :test do 32 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 33 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 34end 35 36group :development do 37 # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 38 gem 'web-console', '>= 3.3.0' 39 gem 'listen', '>= 3.0.5', '< 3.2' 40 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 41 gem 'spring' 42 gem 'spring-watcher-listen', '~> 2.0.0' 43end 44 45group :test do 46 # Adds support for Capybara system testing and selenium driver 47 gem 'capybara', '>= 2.15' 48 gem 'selenium-webdriver' 49 # Easy installation and use of web drivers to run system tests with browsers 50 gem 'webdrivers' 51end 52 53# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 54gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/11/09 09:39