Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not connect to Postgres Container from pgAdmin

related posts: 1) docker postgres pgadmin local connection

2) https://coderwall.com/p/qsr3yq/postgresql-with-docker-on-os-x (in the example "Name" entry is not filled in)

there are two ways to complete this task, I use official postgres

METHOD 1:

and runs it with

sudo docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres

then connect with

Name: postgres
Host: localhost
Port: 5432
user
pass
...

METHOD 2:

starts with

sudo docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres

and then check the ip of container

sudo docker inspect

say result

172.17.42.1

then connect with pgAdmin tab Properties filled info

Name: postgres
Host: 172.17.42.1
Port: 5432
user
pass
...
like image 230
Hello lad Avatar asked Aug 03 '15 23:08

Hello lad


2 Answers

I included this in the docker yaml file to get the database and pgAdmin:

database:
    image: postgres:10.4-alpine
    container_name: kafka-nodejs-example-database
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    expose:
      - "5432"
    ports:
      - 8000:5432
    volumes:
      - ./services/database/schema.sql:/docker-entrypoint-initdb.d/1-schema.sql
      - ./services/database/seed.sql:/docker-entrypoint-initdb.d/2-seed.sql
  pgadmin:
    image: dpage/pgadmin4
    ports:
      - 5454:5454/tcp
    environment:
      - [email protected]
      - PGADMIN_DEFAULT_PASSWORD=postgres
      - PGADMIN_LISTEN_PORT=5454

The postgres username is alphaone and the password is xxxxxxxxxxx.

Do a docker ps to get the container id and then docker inspect <dockerContainerId> | grep IPAddress

eg: docker inspect 2f50fabe8a87 | grep IPAddress

Insert the Ip address into pgAdmin and the database credentials used in docker:

pgAdmin

like image 158
Afshin Ghazi Avatar answered Nov 15 '22 06:11

Afshin Ghazi


Since you're mapping the port 5432 on the container to the same port on host with -p 5432:5432 in your docker run statement, try connecting pgadmin to port 5432 on the host instead of the container.

like image 40
Dharmit Avatar answered Nov 15 '22 06:11

Dharmit