railsプロジェクト作成中、
database.ymlで設定されているmysqlのpasswordとhostが変更できないために開発環境が整いません。所定の部分を書き直し、保存を試みても「'database.yml'の保存に失敗しました」という表示が出ます。
環境としては、WSL2上のubuntuにdockerを用いています。
docker-compose run web rails new . --force --database=mysql --skip-bundleを実行する際に使用したファイルなど記載しておきます。
よろしくお願い致します。
Gemfile
source 'https://rubygems.org' gem 'rails', '5.2.4.1'
Dockerfile
FROM ruby:2.7.0 RUN apt-get update -qq && \ apt-get install -y build-essential \ libpq-dev \ nodejs RUN mkdir /app_name ENV APP_ROOT /app_name WORKDIR $APP_ROOT ADD ./Gemfile $APP_ROOT/Gemfile ADD ./Gemfile.lock $APP_ROOT/Gemfile.lock RUN bundle install ADD . $APP_ROOT
docker-compose.yml
version:
1services: 2 db: 3 image: mysql:5.7 4 environment: 5 MYSQL_ROOT_PASSWORD: password 6 MYSQL_DATABASE: root 7 ports: 8 - "3306:3306" 9 10 web: 11 build: . 12 command: rails s -p 3000 -b '0.0.0.0' 13 volumes: 14 - .:/app_name 15 ports: 16 - "3000:3000" 17 links: 18 - db
問題のconfig/database.yml
# MySQL. Versions 5.1.10 and up are supported. # # Install the MySQL driver # gem install mysql2 # # Ensure the MySQL gem is defined in your Gemfile # gem 'mysql2' # # And be sure to use new-style password hashing: # https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html # default: &default adapter: mysql2 encoding: utf8 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: root password: host: loclahost development: <<: *default database: app_name_development # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: app_name_test # As with config/secrets.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is # ever seen by anyone, they now have access to your database. # # Instead, provide the password as a unix environment variable when you boot # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database # for a full rundown on how to provide these environment variables in a # production deployment. # # On Heroku and other platform providers, you may have a full connection URL # available as an environment variable. For example: # # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" # # You can use this database configuration with: # # production: # url: <%= ENV['DATABASE_URL'] %> # production: <<: *default database: app_name_production username: app_name password: <%= ENV['APP_NAME_DATABASE_PASSWORD'] %>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/03/14 02:49
2020/03/14 02:52