I am having the same issue as here, but with Docker-Compose. Docker container for Postgres 9.1 not exposing port 5432 to host
Please, note, that I am running Docker on Windows 10.
This is the error that I am still getting
And yes, I've tried using docker inspect with container id and indeed got db IP address and managed to connect to it in PGAdmin, but that IP address changes every time I rerun the container. For example: at one launch it was 172.22.02 and at the next one it was 172.19.0.3 .
When I deploy my whole application I will need to refer to postgresql database by a stable, not-changing IP address, else, I suppose, my application will not start correctly even once.
I have 4 containers in docker-compose: redis, redis-insight, PGAdmin and postgresql. I successfully access these containers:
- redis via localhost:6379
- redis_insight via localhost:6380
- pgadmin via localhost:8080
But I can't access db (which is postgresql db) via localhost:5432 .
It just makes no sense to me, and I've wasted several hours searching for a solution, I have absolutely no idea how to solve this.
Please, help me. Thanks.
This is my docker-compose.yml:
version: '3.8'
services:
db:
image: postgres:14.1-alpine3.15
ports:
- '5432:5432'
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=1234
- POSTGRES_DB=telegram_bot_db
restart: always
container_name: db
volumes:
- db:/var/lib/postgresql/data
pgadmin:
image: dpage/pgadmin4:latest
container_name: pgadmin
restart: always
depends_on:
- db
environment:
PGADMIN_DEFAULT_EMAIL: some@nicemail.com
PGADMIN_DEFAULT_PASSWORD: nice
PGADMIN_LISTEN_PORT: 80
ports:
- '8080:80'
volumes:
- pgadmin:/var/lib/pgadmin
redis:
image: redis
container_name: redis
restart: always
ports:
- '6379:6379'
command: redis-server --save 20 1 --loglevel warning --requirepass qwe123qwe
volumes:
- redis:/data
redis_insight:
image: redislabs/redisinsight:latest
container_name: redis_insight
restart: always
depends_on:
- redis
ports:
- '6380:8001'
volumes:
- redis_insight:/db
volumes:
db:
driver: local
redis:
driver: local
redis_insight:
driver: local
pgadmin:
driver: local