Answer the question
In order to leave comments, you need to log in
Docker. docker compose. How to connect a container to another container?
I have a python script that requests data from postgres inside docker. Locally everything works fine, but in the docker it's a disaster. Python cannot connect to Postgres container. I connected them in docker-compose, tried to add them to the general network, nothing happened. Please help, we need to make sure that the container with the script contacts the database container for data transfer.
My docker-compose:
version: '3.8'
services:
script:
build: ./script/
command: /script/src/script.py
container_name: script-mtg
depends_on:
- db
db:
image: postgres:latest
container_name: dbpg-mtg
restart: always
volumes:
- ./ .database/postgres/data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=users
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- "5432"
Answer the question
In order to leave comments, you need to log in
docker-compose raises its own isolated dns.
There is a suspicion that you are connecting to postgres on the localhost:5432 server, and under compose you need db:5432
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question