Install Pgweb Inside Docker Container in Linux

Install Pgweb Inside Docker Container in Linux

Pgweb is a web-based management tool for PostgreSQL database. It allows users to connect to a database and perform various tasks such as run SQL queries, browse database objects, manage data, and more.

This tutorial explains how to install Pgweb 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.

You also need to have a running PostgreSQL container. Instructions can be found in the post.

Install Pgweb

  • Host network

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

docker run -d --name=pgweb --restart=always --network=host \
    -e PGWEB_DATABASE_URL=postgres://postgres:pwd123@127.0.0.1:5432?sslmode=disable \
    sosedoff/pgweb

PostgreSQL container should run on host network as well.

  • User-defined bridge network

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

docker network create app-net
docker run -d --name=pgweb --restart=always --network=app-net \
    -p 8080:8081 \
    -e PGWEB_DATABASE_URL=postgres://postgres:pwd123@postgresql:5432?sslmode=disable \
    sosedoff/pgweb

PostgreSQL container should run on the same user-defined bridge network as well.

Notes:

  • The PGWEB_DATABASE_URL parameter can be used to specify PostgreSQL credentials, host and port: postgres://user:password@host:port.
  • When a user-defined bridge network is used, a PostgreSQL container name is specified in a host part.

Testing Pgweb

To access a web interface, open a web browser and go to http://<IP_ADDRESS>:8081, where <IP_ADDRESS> is the IP address of the system.

Pgweb Inside Docker Container in Linux

Uninstall Pgweb

To completely remove Pgweb, remove its container:

docker rm --force pgweb

Remove Pgweb image:

docker rmi sosedoff/pgweb

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.