Accessing PostgreSQL on docker container from pgAdmin4 in another docker container

ravy amiry

I have a PostgreSQL instance running on a docker with these commands:

mkdir -p $HOME/vols/postgres

docker pull postgres:12.0

docker run --rm   --name pg-docker -e POSTGRES_PASSWORD=docker \
    -v $HOME/vols/postgres:/var/lib/postgresql/data \
    -d -p 5432:5432  postgres

It's up and running and I can access it from DBeaver which is installed on my local-machine. Also, I've installed pgAdmin4 by these commands:

mkdir -p $HOME/vols/pgadmin4

docker pull dpage/pgadmin4

docker run --rm --name pgadmin4 -p 5050:80 \    
    -v $HOME/vols/pgadmin4:/var/lib/pgadmin \
    -e '[email protected]' \
    -e 'PGADMIN_DEFAULT_PASSWORD=12345678' \
    -d dpage/pgadmin4

The pgAdmin is also up and running well and I can easily access it and login to it through http://localhost:5050.

But when I want to connect to my postgre-container instance via pgAdmin4-container instance, I get this error:

Unable to connect to server:

could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? could not connect to server: Address not available Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?

Does anybody has an idea what's going wrong here please? Thanks in advance.

NOTE: My host machine is Fedora 31.

larsks

Inside a container, the loopback address (localhost or 127.0.0.1) refers to "this container". When you try to connect to 127.0.0.1 inside the pgAdmin4 container, it fails because your Postgres service is not running inside the pgAdmin4 container.

The easiest way to make this work is to put both of your containers on a user defined network, in which case they can simply refer to each other by name.

Start by creating a network:

docker network create dbnet

Then launch the postgres container on that network:

docker run --rm --name pg-docker -e POSTGRES_PASSWORD=docker \
    --net dbnet \
    -v $HOME/vols/postgres:/var/lib/postgresql/data \
    -d -p 5432:5432  postgres

And finally launch the pgAdmin4 container on that network:

docker run --rm --name pgadmin4 -p 5050:80 \    
    --net dbnet \
    -v $HOME/vols/pgadmin4:/var/lib/pgadmin \
    -e '[email protected]' \
    -e 'PGADMIN_DEFAULT_PASSWORD=12345678' \
    -d dpage/pgadmin4

Now when you access your pgadmin ui, you can connect to the host pg-docker instead of localhost.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Docker container communication restrictions

분류에서Dev

NCurses in Docker Container

분류에서Dev

AspNetMVC4 installation in Windows Docker container

분류에서Dev

Installing mongo client in a Docker container

분류에서Dev

SSH reverse tunnel into Docker container

분류에서Dev

Internal Tomcat REST calls to localhost from inside Docker container

분류에서Dev

How to find volume files from host while inside docker container?

분류에서Dev

Accessing Docker Services from Host

분류에서Dev

Running a ubuntu container in background using docker compose

분류에서Dev

Docker Container run -d 플래그

분류에서Dev

Connecting to remote activemq instance running on docker container

분류에서Dev

Docker container nodejs connection to external mysql fail

분류에서Dev

Running a script in Docker container by accepting -e parameter

분류에서Dev

WordPress Docker Container에 연결

분류에서Dev

Redirect subdomain to Docker container using NGINX

분류에서Dev

Ansible, docker_container 및 dependent_on

분류에서Dev

Copy schema from one container to another

분류에서Dev

pgadmin4 클라이언트가있는 Docker Toolbox를 사용하여 postgresql 인스턴스에 연결하는 방법

분류에서Dev

TypeORM + pgAdmin4를 사용하여 Docker에서 실행중인 로컬 PostgreSQL 데이터베이스에 연결할 수 없습니다.

분류에서Dev

Why kernel version doesn't match Ubuntu version in a Docker container?

분류에서Dev

Azure Web App for Container의 Docker 웹앱

분류에서Dev

Connecting Robo 3T to Docker MongoDB container

분류에서Dev

Docker Compose Wait til dependency container is fully up before launching

분류에서Dev

Seeding data in a Mongo db within a linked Docker container

분류에서Dev

openssh-server doesn't start in Docker container

분류에서Dev

Docker container doesn't write in amazon EBS volume

분류에서Dev

How to run OpenCL program in Docker container with AMDGPU-Pro?

분류에서Dev

How to configure Amazon container service without docker hub integration

분류에서Dev

Is apt-get dist-upgrade required in Docker container?

Related 관련 기사

  1. 1

    Docker container communication restrictions

  2. 2

    NCurses in Docker Container

  3. 3

    AspNetMVC4 installation in Windows Docker container

  4. 4

    Installing mongo client in a Docker container

  5. 5

    SSH reverse tunnel into Docker container

  6. 6

    Internal Tomcat REST calls to localhost from inside Docker container

  7. 7

    How to find volume files from host while inside docker container?

  8. 8

    Accessing Docker Services from Host

  9. 9

    Running a ubuntu container in background using docker compose

  10. 10

    Docker Container run -d 플래그

  11. 11

    Connecting to remote activemq instance running on docker container

  12. 12

    Docker container nodejs connection to external mysql fail

  13. 13

    Running a script in Docker container by accepting -e parameter

  14. 14

    WordPress Docker Container에 연결

  15. 15

    Redirect subdomain to Docker container using NGINX

  16. 16

    Ansible, docker_container 및 dependent_on

  17. 17

    Copy schema from one container to another

  18. 18

    pgadmin4 클라이언트가있는 Docker Toolbox를 사용하여 postgresql 인스턴스에 연결하는 방법

  19. 19

    TypeORM + pgAdmin4를 사용하여 Docker에서 실행중인 로컬 PostgreSQL 데이터베이스에 연결할 수 없습니다.

  20. 20

    Why kernel version doesn't match Ubuntu version in a Docker container?

  21. 21

    Azure Web App for Container의 Docker 웹앱

  22. 22

    Connecting Robo 3T to Docker MongoDB container

  23. 23

    Docker Compose Wait til dependency container is fully up before launching

  24. 24

    Seeding data in a Mongo db within a linked Docker container

  25. 25

    openssh-server doesn't start in Docker container

  26. 26

    Docker container doesn't write in amazon EBS volume

  27. 27

    How to run OpenCL program in Docker container with AMDGPU-Pro?

  28. 28

    How to configure Amazon container service without docker hub integration

  29. 29

    Is apt-get dist-upgrade required in Docker container?

뜨겁다태그

보관