1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

rails×Docker導入でのエラー②「django.db.utils.OperationalError: could not translate host name "db" to address: Name or service not known」

Last updated at Posted at 2020-06-13

##エラー発生

rails newに成功し、各ファイルが増えたものの
下記のエラーが出てしまった。

Docker-error01.png

exited with code 1 はただアプリケーションエラーという意味らしい。

幸いにも、railsの起動は出来ていたので
そちらの方にヒントとなるエラー文が。

「django.db.utils.OperationalError: could not translate host name "db" to address: Name or service not known」

##解決策

環境変数を加えたら、解決しました。

###修正前

docker-compose.yml
  db:
    image: postgres
    volumes:
      - ./tmp/db:/var/lib/postgresql/data

###修正後

docker-compose.yml
  db:
    image: postgres
    ports: 
        - "5432"
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    volumes:
      - ./tmp/db:/var/lib/postgresql/data

パスワードなどの受け渡しがうまくいっていなかった?
ようで、しっかりと情報を明記したら通るようになりました!

以上。

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?