Install pgAdmin Inside Docker Container in Linux

Install pgAdmin Inside Docker Container in Linux

The pgAdmin is a management tool for PostgreSQL database through a web browser. The pgAdmin is an open-source project available under the PostgreSQL license.

This tutorial explains how to install pgAdmin inside a Docker container in the Linux. Commands have been tested on Ubuntu.

Prepare environment

Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.

Install pgAdmin

Before starting, create directory for data:

sudo mkdir -p /opt/pgadmin/data

Set user, which ID is 5050 as owner for newly created directory:

sudo chown -R 5050:5050 /opt/pgadmin

Note: it doesn't matter that user (ID: 5050) doesn't exist on host system. This user will be created in the container.

  • Host network

Run the following command to create a container for pgAdmin that uses host network:

docker run -d --name=pgadmin --restart=always --network=host \
    -e PGADMIN_DEFAULT_EMAIL=admin@example.com \
    -e PGADMIN_DEFAULT_PASSWORD=pwd123 \
    -v /opt/pgadmin/data:/var/lib/pgadmin \
    dpage/pgadmin4
  • User-defined bridge network

User-defined bridge network can be used for listening on different port. By default, pgAdmin service is listening on port 80. It can be changed with -p option.

docker network create app-net
docker run -d --name=pgadmin --restart=always --network=app-net \
    -p 8080:80 \
    -e PGADMIN_DEFAULT_EMAIL=admin@example.com \
    -e PGADMIN_DEFAULT_PASSWORD=pwd123 \
    -v /opt/pgadmin/data:/var/lib/pgadmin \
    dpage/pgadmin4

Note: don't forget to change admin email and password.

Testing pgAdmin

Open a web browser and go to http://<IP_ADDRESS>, where <IP_ADDRESS> is the IP address of the system. Log in to the dashboard using email and password.

pgAdmin Inside Docker Container in Linux

Uninstall pgAdmin

To completely remove pgAdmin, remove its container:

docker rm --force pgadmin

Remove pgAdmin image:

docker rmi dpage/pgadmin4

You can also remove pgAdmin data:

sudo rm -rf /opt/pgadmin

If a user-defined bridge network was created, you can delete it as follows:

docker network rm app-net

Leave a Comment

Cancel reply

Your email address will not be published.