docker postgres pgadmin local connection

前端 未结 16 2159
清歌不尽
清歌不尽 2020-12-02 06:44

I have created an ubuntu image with nginx, php and postgres.

I want to connect the postgres database in my current image with pgadmin located on my loca

相关标签:
16条回答
  • 2020-12-02 06:58

    You can create a Docker bridge network to do this too.

    $ docker network create pgnet
    a0ae44aaf6f806fc37302e4c603b4828c4edb8d487fd9cd90e2fb19ae1d5c65f
    
    $ docker run --detach \
        --name pg \
        --network pgnet \
        --publish 5432:5432 \
        --restart always \
        --env POSTGRES_PASSWORD=pg123 \
        --volume ${PWD}/data:/var/lib/postgresql/data \
        postgres:12.1
    b60611e43727dabe483c1f08fdf74961b886ce05b432a10a0625bd1b6db87899
    
    $ docker run --detach \
        --name pgadm \
        --network pgnet \
        --publish 8000:80 \
        --volume ${PWD}/pgadmin:/var/lib/pgadmin \
        --env PGADMIN_DEFAULT_EMAIL=user@domain.com \
        --env PGADMIN_DEFAULT_PASSWORD=pgadm123 \
        dpage/pgadmin4:4.20
    27f9ce1c1c4c383ee1507f4e2d88f6ef33d4fcf5b209a8a03b87519f90d56312
    

    Open http://localhost:8000/

    1. Click Add New Server
    2. Create - Server
      1. Name: db
      2. Hostname/address: pg
      3. Username: postgres
      4. Password: pg123
    3. Save

    The Hostname/address used above is the name of the Postgres container given by --name pg

    0 讨论(0)
  • 2020-12-02 07:01

    In my case I could solve the problem inspecting my postgre image through command

    docker inspect CONTAINER_ID  | grep IPAddress.
    

    So, I used the docker ip address to config my pgadmin 4 connection and everything was fine. Thanks to @Afshin Ghazi

    0 讨论(0)
  • 2020-12-02 07:02

    This is what i did

    for postgres

    docker run -p 5432:5432  --name container-postgresdb -e POSTGRES_PASSWORD=admin -d postgres
    

    for pgadmin

    docker run -p 5050:80  -e "PGADMIN_DEFAULT_EMAIL=name@example.com" -e "PGADMIN_DEFAULT_PASSWORD=admin"  -d dpage/pgadmin4
    

    Connection string for pgadmin

    host: host.docker.internal
    database: postgres
    user: postgres
    password: admin
    

    It works fine!!!!!

    0 讨论(0)
  • 2020-12-02 07:04

    What I have done success on windows 10 running docker for windows 1.12.6(9655), the step is like below:

    1. Pull the latest postgres

      docker pull postgres:latest

    2. run the postgres containner:

      docker run -d -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password123 --name db-my -p 5432:5432 --restart=always postgres

    3. Then installed the latest version of pgAdmin4 from pgadmin website

    4. Run pgAdmin 4 create new server, and input as following Host: 127.0.0.1 Port: 5432 User name: user password: password123

    5. Then everything is ok, connect to docker postgres instance success.
    0 讨论(0)
  • 2020-12-02 07:04

    In order or find your IP of the container, use following command

    docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id
    

    Referrence: How to get a Docker container's IP address from the host

    0 讨论(0)
  • 2020-12-02 07:04

    For macOS IPs of postgres and pgadmin4 are different from the ones docker inspect provides. Type

    docker-machine ls
    

    Take a look at the name of the server on the left. It's default by default.

    docker-machine ip default will IP you need to use for both, pgadmin4 in browser and for postgres in pgadmin4 settings.

    0 讨论(0)
提交回复
热议问题