#環境
Mac os Catalina -v10.15.4
Ruby Mine
#やりたいこと
RailsのAPIをDockerでpostgresを動かしながら作成しようとしています
docker-compose.ymlは以下のようになります。
version: '3' services: db: image: postgres:12.2 environment: - DATABASE_HOST=localhost - POSTGRES_USER=$API_DB_DEV_USERNAME - POSTGRES_PASSWORD=$API_DB_DEV_PASSWORD - PGPASSWORD=$API_DB_DEV_PASSWORD ports: - "5432:5432" volumes: - datavol:/var/lib/postgresql/data volumes: datavol:
追記(04/12/18:37)
database.yamlは以下のようになります
# PostgreSQL. Versions 9.3 and up are supported. # # Install the pg driver: # gem install pg # On macOS with Homebrew: # gem install pg -- --with-pg-config=/usr/local/bin/pg_config # On macOS with MacPorts: # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config # On Windows: # gem install pg # Choose the win32 build. # Install PostgreSQL and put its /bin directory on your path. # # Configure Using Gemfile # gem 'pg' # default: &default adapter: postgresql encoding: unicode # For details on connection pooling, see Rails configuration guide # https://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> development: <<: *default database: bokin_back_development # The specified database role being used to connect to postgres. # To create additional roles in postgres see `$ createuser --help`. # When left blank, postgres will use the default role. This is # the same name as the operating system user that initialized the database. #username: bokin_back # The password associated with the postgres role (username). #password: # Connect on a TCP socket. Omitted by default since the client uses a # domain socket that doesn't need configuration. Windows does not have # domain sockets, so uncomment these lines. #host: localhost # The TCP port the server listens on. Defaults to 5432. # If your server runs on a different port number, change accordingly. #port: 5432 # Schema search path. The server defaults to $user,public #schema_search_path: myapp,sharedapp,public # Minimum log levels, in increasing order: # debug5, debug4, debug3, debug2, debug1, # log, notice, warning, error, fatal, and panic # Defaults to warning. #min_messages: notice # 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: bokin_back_test # As with config/credentials.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 https://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="postgres://myuser:mypass@localhost/somedatabase" # # You can use this database configuration with: # # production: # url: <%= ENV['DATABASE_URL'] %> # production: <<: *default database: bokin_back_production username: bokin_back password: <%= ENV['BOKIN_BACK_DATABASE_PASSWORD'] %>
zshの環境変数にはPOSGRES_USERとPOSGRES_PASSWORDを記述しました.
開発ディレクトリにて、docker-compose up -d
を実行して
rails db:migrate
を実行したのですがエラーが出て、困っています
#エラー
rails db:migrate
を実行したログがこちらです。
user@ts21-2 app_back % rails db:migrate Warning: the running version of Bundler (2.1.2) is older than the version that created the lockfile (2.1.4). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.1.4`. /Users/ts/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.2/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call /Users/ts/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.2/lib/action_dispatch/middleware/static.rb:110: warning: The called method `initialize' is defined here /Users/ts/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.2.2/lib/active_record/type.rb:27: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call /Users/ts/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.2.2/lib/active_record/type/adapter_specific_registry.rb:9: warning: The called method `add_modifier' is defined here rails aborted! PG::ConnectionBad: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"? /Users/ts/RubymineProjects/app_back/bin/rails:9:in `<top (required)>' /Users/ts/RubymineProjects/app_back/bin/spring:15:in `<top (required)>' bin/rails:3:in `load' bin/rails:3:in `<main>' Tasks: TOP => db:migrate (See full trace by running task with --trace)
posgresのサーバに接続していないのが原因のようです
直接関係ないとbundlerのバージョンは2.1.4のはずですがwarningがでてました
ts@ts21-2 app_back % bundler -v Bundler version 2.1.4
#やったこと
同じエラーの記事を参考に
$ brew services start postgresql
と再起動を実行した上で、再びrails db:migrate
しましたが、上記エラーがでました
(そもそも、これはDockerと関係あるのか?)
#憶測
Dockerを立てて posgreを使うのが今回初めてなので、もしかするとDockerの設定に間違いがあるのか
と思っています。
回答1件
あなたの回答
tips
プレビュー