0

I am connecting to a postgresql docker service with the following commands :

docker create --name postgres-demo -e POSTGRES_PASSWORD=Welcome -p 5432:5432 postgres:11.5-alpine
docker start postgres-demo
docker exec -it postgres-demo psql -U postgres

I can successfully connect to postgresql conatiner service enter image description here

Now I want to connect to PgAdmin4 to make some queries to the existing data in postgres database However I keep having this error enter image description here

The IP address that I am using is the one I extracted from docker inspect DOCKERID

enter image description here

I have restarted the postgresql service on windows but nothing happens. What I am doing wrong ?

Thanks

2 Answers 2

2

In fact, what you get with docker inspect(172.17.0.2) is just the ip of container, to visit the service in container, you need port binding host's port to container's port.

I see you already used -p 5432:5432 to do it, so please get the ip of host using ip a s, then if you get e.g. 10.10.0.186, then use this host ip to visit the service, use 5432 as a port.

To publish a port for our container, we’ll use the --publish flag (-p for short) on the docker run command. The format of the --publish command is [host port]:[container port]. So if we wanted to expose port 8000 inside the container to port 3000 outside the container, we would pass 3000:8000 to the --publish flag.

A diagram let you know the topologic of docker network, FYI:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

You should try to connect to:

host: 0.0.0.0
port: 5432

while your docker container is up and running.

1 Comment

I needed to close my postgresql service and only have my docker up and running

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.