現在Dockerについて勉強をしようと思い、
https://www.youtube.com/watch?v=ltDdZAJli8c
上記の動画を参考にDockerの基本アプリを作成しています
docker-compose run web rails new . --force --database=mysql を行い、railsの基本ファイル、ディレクトリを作成
docker-compose buildを行い、イメージの作成
までは進んだのですが、
docker-compose run web rails db:createを行った際エラーになってしまいデータベースを作成しようとしたところ以下のエラーが出てきます。
エラー文を抜粋して見ると
iTerm
1Mysql2::Error: Failed to create schema directory 'app_development' (errno: 2 - No such file or directory) 2Couldn't create 'app_development' database. Please check your configuration. 3rake aborted! 4ActiveRecord::StatementInvalid: Mysql2::Error: Failed to create schema directory 'app_development' (errno: 2 - No such file or directory)
そのようなファイルまたはディレクトリはありませんと言われています。
わからない部分
これはどこにファイルまたはディレクトリがありませんと言われているのかがわからず困っております。
わかる方がいらっしゃいましたらご回答、よろしくお願い致します。
以下、関係のありそうなファイルです
docker
1version: '3' 2#dbとwebのサービスを定義 3services: 4 db: #msql 5 image: mysql:8.0 6 command: --default-authentication-plugin=mysql_native_password #認証形式の設定8.0から 7 volumes: 8 - ./src/db/mysql_data:/var/lib/mysql #./src/db/mysql_data(ローカル)を/var/lib/mysql(docker)側に共有する設定(コンテナを作り直すたびにデータが消えてしまうが、これを設定しておけばローカルのデータを持ってこれる) 9 environment: 10 MYSQL_ROOT_PASSWORD: password #(環境変数でパスワードを指定) 11 web: #rails 12 build: . #ベースのイメージとしてDocker fileを参照する設定 13 command: bundle exec rails s -p 3000 -b '0.0.0.0' #rails サーバーを起動 14 volumes: 15 - ./src:/app #./src(ローカル)内を/app(Docker)側に共有する 16 ports: 17 - "3000:3000" #ローカルの3000ポートをDockerの3000ポートに接続 18 depends_on: #webはdbサービスに依存しているという設定 19 - db
Dockerfile
1FROM ruby:2.7 2 3RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \ 4 && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \ 5 && apt-get update -qq \ 6 && apt-get install -y nodejs yarn 7 #必要なライブラリをインストール 8WORKDIR /app 9#作業ディレクトリを指定/app 10COPY ./src /app 11#./srcローカル側を/appにコピー 12RUN bundle config --local set path 'vendor/bundle' \ 13 && bundle install 14#bundle installをする
datebase.yml
1# MySQL. Versions 5.5.8 and up are supported. 2# 3# Install the MySQL driver 4# gem install mysql2 5# 6# Ensure the MySQL gem is defined in your Gemfile 7# gem 'mysql2' 8# 9# And be sure to use new-style password hashing: 10# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html 11# 12default: &default 13 adapter: mysql2 14 encoding: utf8mb4 15 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 16 username: root 17 password: password 18 host: db 19 20development: 21 <<: *default 22 database: app_development 23 24# Warning: The database defined as "test" will be erased and 25# re-generated from your development database when you run "rake". 26# Do not set this db to the same as development or production. 27test: 28 <<: *default 29 database: app_test 30 31# As with config/credentials.yml, you never want to store sensitive information, 32# like your database password, in your source code. If your source code is 33# ever seen by anyone, they now have access to your database. 34# 35# Instead, provide the password or a full connection URL as an environment 36# variable when you boot the app. For example: 37# 38# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" 39# 40# If the connection URL is provided in the special DATABASE_URL environment 41# variable, Rails will automatically merge its configuration values on top of 42# the values provided in this file. Alternatively, you can specify a connection 43# URL environment variable explicitly: 44# 45# production: 46# url: <%= ENV['MY_APP_DATABASE_URL'] %> 47# 48# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database 49# for a full overview on how database connection configuration can be specified. 50# 51production: 52 <<: *default 53 database: app_production 54 username: app 55 password: <%= ENV['APP_DATABASE_PASSWORD'] %>

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。