Cant connect to postgres from another python container. All started from same docker-compose

Hello,

i tried to connect to an existing postgres sql from another docker container within same instanz but i cant get it working. Any ideas? I already searched the internet but nothing is workin. I think its an obvious mistake but i dont see it …

yaml:

version: ‘3’

services:

raw_data_db:
image: postgres:latest
container_name: raw_data_db
environment:
POSTGRES_DB: raw_data
POSTGRES_USER: my_username
POSTGRES_PASSWORD: my_password
ports:
- “5434:5434”
volumes:
- /path/to/store/data:/var/lib/postgresql/data

zookeeper:
image: confluentinc/cp-zookeeper:latest
container_name: zookeeper
ports:
- “2181:2181”
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000

broker:
image: confluentinc/cp-enterprise-kafka:latest
container_name: broker
ports:
- “9092:9092”
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:9092
depends_on:
- zookeeper

producer:
build:
context: .
dockerfile: ./DockerfileProducer
volumes:
- ./producer.py:/app/producer.py
- ./data_cleaned_1000.csv:/app/data_cleaned_1000.csv
command: sh -c “sleep 10 && python /app/producer.py”

consumer:
build:
context: .
dockerfile: ./DockerfileConsumer
volumes:
- ./consumer.py:/app/consumer.py
command: sh -c “sleep 30 && python /app/consumer.py”

For the host i tried everything. Localhost, …

conn = psycopg2.connect(
database=“raw_data”,
user=“my_username”,
password=“my_password”,
host=“raw_data_db”,
port=“5434”
)

I really really appreciate any help. Stuck with this problems since two days

Please, format your post according to the following guide by editing it

In short: Use code blocks, not quotes, especiially for yaml codes. Thank you.

Also please, share error messages, any info, details that helps us to help you without guessing.