docker postgres pgadmin local connection

前端 未结 16 2306
清歌不尽
清歌不尽 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

提交回复
热议问题