Postgres and PGadmin4 on docker

If you need a quick setup for postgres and pgadmin4 here it is what you need:

Create a docker-compose.yml file with the following content:

version: "3"
services:
  postgres_svc:
    image: postgres
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: changeme
      PGDATA: /data/postgres
    ports:
      - "5432:5432"
    networks:
      - postgres
    volumes:
      - ./data:/data
    restart: unless-stopped

  pgadmin_svc:
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@example.com
      PGADMIN_DEFAULT_PASSWORD: admin
    links:
      - postgres_srv:postgres_srv
    volumes:
      - ./data:/data
    ports:
      - "5050:80"
    networks:
      - postgres
    restart: unless-stopped

networks:
  postgres:
    driver: bridge

The above code will instruct docker to create a ./data directory where it will store the database. This way, if you delete the containers you will not lose the databases.

Start containers in docker

docker-compose up

Once it finish, open the url http://localhost:5050 in your browser.

To login use the following credentials that are defined in docker-compose.yaml file:

  • Username: admin@example.com
  • Password:

Add server connection

After you have successfully logged in, click on Add Server button:

Click on Add server button

On the new popup, add a name to the server and then click on Connection tab

On the Connection tab, add the following data:

  • Host name: postgres_svc
  • Username: postgres
  • Password: changeme
  • Check Save password
  • Click and Save to save the configurations

Connection tab

Now you should be able to access your new postgres database