I am running into issue an issue connecting to database (postgres, db-server service as mentioned below) running in a container, and I am trying to access database from the other service ( crawler). Looks like it got the ip address right (I am using hostname as db-server) but, its not able to connect to the db. I am stuck on this for a very long time. Please help!
version: "3.7"
services:
# App Service
go-server:
# container_name: go_server
build: backend
ports:
- 8000:8000
depends_on:
- db-server
networks:
- api-server
#Database
db-server:
# container_name: db_server
image: postgres
restart: always
secrets:
- db-password
volumes:
- ${HOME}/data:/var/lib/postgresql/data
- ./database/scripts/schema.sql:/docker-entrypoint-initdb.d/schema.sql
environment:
- POSTGRES_PASSWORD_FILE=/run/secrets/db-password
expose:
- 5432
networks:
- api-server
crawler:
build: crawler
networks:
- api-server
networks:
api-server: {}
volumes:
pg-data: {}
secrets:
db-password:
file: database/password.txt