Connection to 172.17.0.1:5432 refused

I am trying to up a docker image together of a postgres image. I am using this repository https://github.com/Cambalab/metabase-compose, following the step-by-step.

I've been have success in build image step, and up container step. But after the previous steps, when I have to add a database I am facing this error:

In this case, I am not setting a postgres host in my .env, and I am sure password and username are corrects.
Does anyone have an idea what I am doing wrong?
Thank you!

Hi @vsantos93
If Metabase is running in Docker, and Postgres is running in Docker, then you should point to the Postgres container. You are pointing to the Docker host.
docker inspect db (looks like it calls the Postgres "db").
Otherwise try another guide, example: Docker-compose with persistent configuration settings

1 Like

Since then I have updated that docker-compose to include PG + Metabase and a few others.

In this example the host is just db

1 Like

Thank you so much @flamber and @brunoamaral , it works as a charm!

My team and I thought we don't need a database in this docker-compose.

So, the docker-compose.yml file become:

services:
    metabase:
      volumes:
        - ./metabase-data:/metabase-data
      environment:
        - MB_DB_FILE=/metabase-data/metabase.db
        - MB_DB_TYPE=postgres
        - MB_DB_DBNAME=db_name
        - MB_DB_PORT=5432
        - MB_DB_USER=postgres
        - MB_DB_PASS=password
        - MB_DB_HOST=host
      ports:
        - 3000:3000
      image: metabase/metabase
      restart: always

And it worked even I don't know if this is the best way to do this.
But after I built the database, I needed to input my database credentials. Is there a way to avoid this and make the metabase up with the inserted in docker-compose credentials?
Thank you!

1 Like

check this out: https://www.metabase.com/docs/latest/operations-guide/running-metabase-on-docker.html#use-docker-secrets-to-hide-sensitive-parameters

@vsantos93 You do not need MB_DB_FILE nor the volumes, since that is the H2, which you are not using.

Thanks @flamber, I was able to remove this env variable.

The database I set in env file is used to store metabase records, is it?
I've been reading about the documentation which @Luiggi post above, but it not be clear to me. I am trying to make metabase record in the same database where I have my data to analyse, and I would like to avoid the initial database setup because it has the same credencials as the database I am using in docker-compose.yml. Can I do this?

@vsantos93 Yes, all Metabase data is stored in the "application database":
https://www.metabase.com/docs/latest/operations-guide/configuring-application-database.html

You can use an existing Postgres/MySQL if you prefer, but you should use an empty database and different credentials.

You cannot setup your data sources with environment variables. You would have to use the API:
https://www.metabase.com/docs/latest/api-documentation.html