Connecting to Postgres (.internal) from Dockerfile on deploy


I am having issues connecting to a Postgres application through a Dockerfile on deploy. The database is available when connecting from directly from the application itself (i.e fly ssh console).

P1001: Can't reach database server at `postgres.internal`:`5432`                                                        
Please make sure your database server is running at `postgres.internal`:`5432`.                                         

Any help on the matter would be greatly appreciated.

Best regards,

Hi Alex,

Just to confirm, have you been through this:

Also from this page:

Note that for the app to be able to attach to the database it must have private_network enabled in fly.toml.

If you’ve already reviewed these, please paste the fly.toml and the dockerfile here.


1 Like

Hi FrequentFlyer,

Private network is enabled:

app = "backend"

kill_signal = "SIGINT"
kill_timeout = 5
processes = []

  LOG_LEVEL = "debug"
  PORT = 8080

  allowed_public_ports = []
  auto_rollback = true
  private_network = true

  http_checks = []
  internal_port = 8080
  processes = ["app"]
  protocol = "tcp"
  script_checks = []

    hard_limit = 25
    soft_limit = 20
    type = "connections"

    handlers = ["http"]
    port = 80

    handlers = ["tls", "http"]
    port = 443

    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"
ENV NODE_ENV=production
ENV DATABASE_URL=postgres://backend:[PASSWORD]@top2.nearest.of.postgres.internal:5432/backend
COPY . .
RUN yarn prisma generate
RUN yarn build
RUN yarn prisma migrate status 
USER node
ENTRYPOINT ["node", "dist"]

Best regards,

What is the name of your database application? It’s probably not postgres. If you app name is my-postgres-cluster then your DATABASE_URL should also contain it, like:


One thing: setting the DATABASE_URL in the Dockerfile is insecure as it will show up when inspecting images.

Instead, you can run yarn prisma migrate as a release command instead of requiring your build to access the database. Release commands run after build, but before deployment, and they inherit the app environment/secrets. Builds do not.

See App Configuration (fly.toml)

Also: private networks are enabled by default, so you no longer need to add this to your fly.toml explicitly.

1 Like