docker postgres pgadmin local connection

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

    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:
          - PGADMIN_DEFAULT_EMAIL=admin@mydomain.com
          - 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 | grep IPAddress

    eg: docker inspect 2f50fabe8a87 | grep IPAddress

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

提交回复
热议问题