#docker container cannot connect to postgres

5 messages · Page 1 of 1 (latest)

pastel epoch
#

I'm trying to run a docker container by following the multi stage build process here https://backstage.io/docs/deployment/docker/

I already have a postgres instance running and the application connects successfully when using yarn dev . However, I get this error when running the docker container: Error: Failed to connect to the database to make sure that 'backstage_plugin_app' exists, Error: connect ECONNREFUSED 127.0.0.1:5432

Here is what I have in both app-config.yml and app-config.production.yml

    client: pg
    connection:
      host: ${POSTGRES_HOST}
      port: ${POSTGRES_PORT}
      user: ${POSTGRES_USER}
      password: ${POSTGRES_PASSWORD}
      ssl:
        require: true
        rejectUnauthorized: true 

And I'm attaching my Dockerfile at the bottom

The host shouldn't be localhost, it should be what I've specified in POSTGRES_HOST. I think that is the issue but I don't know how to make the docker container point to the right host. Any ideas on how to fix this?

How to build a Backstage Docker image for deployment

olive zealot
#

Where is the postgres instance running, is it in another container. If the postgres is bound to the port of the docker host, you can use host.docker.internal as the postgres host.

pastel epoch
#

the postgres is completely separate in a deployed container

olive zealot
#

I presume the postgres container is configured to bind its port on to the host. So the host name i mentioned should work.

#

Did you try it?