LoginSignup
0
0

More than 1 year has passed since last update.

docker-compose で postgresql が migrate できない

Posted at

docker-compose を使って rails の 環境構築
postgresqlmigrate できなかった

設定ファイルは以下

docker-compose.yml
version: "3"
services:
  db:
    image: postgres
    volumes:
      - pgdatavol:/var/lib/postgresql/data
  web:
    build: .
    command: bundle exec rails s -p 3000 -b "0.0.0.0"
    volumes:
      - .:/myapp
    ports:
      - "3000:3000"
    depends_on:
      - db
volumes:
  pgdatavol:   
database.yml
default: &default
  adapter: postgresql
  encoding: unicode
  host: db
  username: postgresql
  password: 

このあと docker コンテナを立ち上げてから

docker-compose run web rake db:create

docker-compose run web rake db:migrate

すると以下の内容のエラー

ConnectionBad: could not translate host name "db" to address: Name or service not known

なんかわかんないけど hostdb が認識されてない


上の記事を参考にさせていただき、以下のように設定ファイルを変更

docker-compose.yml
version: "3"
services:
  db:
    image: postgres
  environment:
      POSTGRES_USER: 'postgresql'
      POSTGRES_PASSWORD: 'postgresql-pass
    volumes:
      - pgdatavol:/var/lib/postgresql/data
  web:
    build: .
    command: bundle exec rails s -p 3000 -b "0.0.0.0"
    volumes:
      - .:/myapp
    ports:
      - "3000:3000"
    depends_on:
      - db
volumes:
  pgdatavol:   
database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  host: db
  username: postgresql
  password: postgresql-pass

なんか postgresql のセキュリティの観点から
明示的に環境変数に設定するようになったっぽい

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0