Docker docker-compose db:create db:migrate 出来ない
既存アプリケーションの開発環境にdockerを適用させようと思ったのですが、
docker-compose build
の後に、
docker-compose run web rails db:create db:migrate や docker-compose run web bundle exec rails db:create db:migrate
といったコマンドを叩いても、
Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"rails\": executable file not found in $PATH": unknown
と表示されてしまいます。
docker-compose up
上記コマンドは通り、ページを表示しようとしてくれています(migrateされていないので表示自体はできませんが)
色々な記事を参考にしてみたのですが、
どれもうまくいかず途方に暮れている状態です、、、。
もし、これが原因かもしれないなどあれば、ご教示いただけますと幸いです。
開発環境
ruby2.5.5
rails 5.2.4.1
docker 19.03.1
windows 10 home
現状
gemfile
1source 'https://rubygems.org' 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby '2.5.5' 5 6# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 7gem 'rails', '~> 5.2.4' 8# Use sqlite3 as the database for Active Record 9gem 'sqlite3' 10# Use postgresql as the database for Active Record 11gem 'pg', '~> 0.18' 12# Use Puma as the app server 13gem 'puma', '~> 3.11' 14# Use SCSS for stylesheets 15gem 'sass-rails', '~> 5.0' 16# Use Uglifier as compressor for JavaScript assets 17gem 'uglifier', '>= 1.3.0' 18# See https://github.com/rails/execjs#readme for more supported runtimes 19# gem 'mini_racer', platforms: :ruby 20 21# Use CoffeeScript for .coffee assets and views 22gem 'coffee-rails', '~> 4.2' 23# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 24# gem 'turbolinks', '~> 5' 25# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 26gem 'jbuilder', '~> 2.5' 27# Use Redis adapter to run Action Cable in production 28# gem 'redis', '~> 4.0' 29# Use ActiveModel has_secure_password 30# gem 'bcrypt', '~> 3.1.7' 31 32# Use ActiveStorage variant 33# gem 'mini_magick', '~> 4.8' 34 35# Use Capistrano for deployment 36# gem 'capistrano-rails', group: :development 37 38# Reduces boot times through caching; required in config/boot.rb 39gem 'bootsnap', '>= 1.1.0', require: false 40 41group :development, :test do 42 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 43 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 44 gem 'pry-rails' 45 gem 'pry-byebug' 46 gem 'pry-doc' 47 gem 'better_errors','2.5.1' 48 gem 'binding_of_caller','0.8.0' 49 gem 'rspec-rails','3.9.0' 50 gem 'factory_bot_rails','~> 5.1.1' 51end 52 53group :development do 54 # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 55 gem 'web-console', '>= 3.3.0' 56 gem 'listen', '>= 3.0.5', '< 3.2' 57 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 58 gem 'spring' 59 gem 'spring-watcher-listen', '~> 2.0.0' 60end 61
Dockerfile
1FROM ruby:2.5.5 2 3RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/* 4RUN apt-get update && apt-get install -y postgresql-client --no-install-recommends && rm -rf /var/lib/apt/lists/* 5RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs 6 7WORKDIR /myapp 8 9ADD Gemfile /myapp/Gemfile 10ADD Gemfile.lock /myapp/Gemfile.lock 11 12RUN gem install bundler 13RUN bundle install 14 15ADD . /myapp 16 17CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
entrypointsh
1#!/bin/bash 2set -e 3 4# Remove a potentially pre-existing server.pid for Rails. 5rm -f /myapp/tmp/pids/server.pid 6 7# Then exec the container's main process (what's set as CMD in the Dockerfile). 8exec "$@"
dockercomposeyml
1version: '3' 2services: 3 db: 4 image: postgres 5 volumes: 6 - ./tmp/db:/var/lib/postgresql/data 7 web: 8 build: 9 context: . 10 dockerfile: Dockerfile 11 command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" 12 volumes: 13 - .:/myapp 14 ports: 15 - "3000:3000" 16 depends_on: 17 - db
databeseyml
1default: &default 2 adapter: postgresql 3 encoding: unicode 4 host: db 5 username: postgres 6 password: 7 pool: 5 8 9development: 10 <<: *default 11 database: myapp_development 12 13 14test: 15 <<: *default 16 database: myapp_test
他、必要情報などあれば伝えさせていただければと思います。
無駄な情報も多いかもしれませんが、何卒ご容赦頂ければ幸いです。
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。