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

[備忘][Docker][Fastify]DockerにFastifyコンテナを立ち上げたけど、postgresコンテナと接続できなかった件を解決

Posted at

Fastifyコンテナとpostgresコンテナが接続できない

Fastifyのコンテナを起動させると、下記エラーで落ちる。

Error: P1001: Can't reach database server at `localhost`:`5432`

データベースに接続できない模様。

調査結果

エラー内容そのまんまで検索してたらちゃんと公式に書いてあった

When deploying to a Docker, and potentially other, containers, it is advisable to listen on 0.0.0.0 because they do not default to exposing mapped ports to localhost:

つまり、

fastify.listen({ port: 3000 }, (err, address) => {
  if (err) {
    fastify.log.error(err)
    process.exit(1)
  }
})

を以下のようにしてあげる。

fastify.listen({ port: 3000, host: '0.0.0.0' }, (err, address) => {
  if (err) {
    fastify.log.error(err)
    process.exit(1)
  }
})

この辺の理解をしっかりしたいので、別記事にまとめる。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?