I have airflow and postgres running in a docker container that I have hosted on a digital ocean droplet. Airflow is running successfully and writing data to my postgres database. When I ssh into my digital ocean droplet, I can docker exec -it <mycontainer> bash
and from there I can run psql and query my database. I know that it is up and running by inspecting the container, and I have exposed port 5433. I know that there aren't any firewall issues, because I am able to access the airflow webserver/UI from my machine just by going to the droplet ID address and the correct port.
What I would like to do is access the database from my local machine to be able to run queries and do analysis. However, I can not find a way to connect to the database. Ideally I would connect while using a SQL editor (DBeaver).
I have spent 4 hours trying to get the connection to work and I have exhausted all my resources (ChatGPT was unhelpful!). I was able to successfully create a ssh tunnel in DBeaver, but I still wasn't able to get the connection. I get this error, which I don't understand.
The connection attempt failed.
EOFException
java.io.EOFException
I have also gotten the Connection Refused
error message before. That happens when I do not use the ssh tunnel. When I inspect my docker container running on the server, the IPAddress is listed as "172.20.0.2". I have exposed port 5433 in the docker-compose file. I am trying to find the correct connection string (after successfully ssh tunneling).
username: postgres
password: mypassword
database: postgres
port: 5433
host: ? (I haveve tried "localhost" and "172.20.0.2")
Anyone able to save my sanity?
TL;DR Trying to connect to a postgres db running in a docker container on a digital ocean droplet. Container and Postgres is running (I am able to connect to the container and run queries with psql). I also know there aren't any firewall issues, I am able to connect to the airflow dashboard running in a container in the same droplet.
Edit: Here is my docker-compose file for the postgres container
version: '3.8'
services:
jupyter_notebook:
image: "jupyter/minimal-notebook"
container_name: ${CONTAINER_NAME:-jupyter_notebook}
environment:
JUPYTER_ENABLE_LAB: "yes"
ports:
- "8888:8888"
volumes:
- ${PWD}:/home/jovyan/work
depends_on:
- db
links:
- db
networks:
- adu_network
db:
image: postgres:15.2
restart: always
environment:
- "POSTGRES_USER=${POSTGRES_USER}"
- "POSTGRES_PASSWORD=${POSTGRES_PASSWORD}"
- "POSTGRES_PORT=${POSTGRES_PORT}"
- "POSTGRES_HOST=${POSTGRES_HOST}"
ports:
- "5433:5433"
expose:
- "5433"
networks:
- adu_network
volumes:
- ./data:/var/lib/postgresql/data
- ./adu_db.sql:/docker-entrypoint-initdb.d/init.sql
volumes:
db:
driver: local
networks:
adu_network: null