Would you like to learn how to install PostgreSQL using Docker on Ubuntu Linux? In this tutorial, we are going to show you all the steps required to perform the PostgreSQL installation using Docker on a computer running Ubuntu Linux in 5 minutes or less.

• Ubuntu 20.04
• Ubuntu 18.04
• Ubuntu 19.04
• PostgreSQL 12.4

PostgreSQL – Related Tutorial:

On this page, we offer quick access to a list of tutorials related to PostgreSQL.

Tutorial PostgreSQL – Docker Installation on Ubuntu Linux

Install the Docker service.

Copy to Clipboard

Download the PostgreSQL docker image from the online repository.

Copy to Clipboard

List the Docker images installed on your system.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

Start a new PostgreSQL container using this Docker image.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

In our example, the Docker image was used to start a new container.

The new container is using the local port 5432.

The container ID is 970ed08d8647d019c7e5041aa13a73d79496c50e4a657b3fe5e7ba4576b226bf.

The PostgreSQL password configured was kamisama123.

Congratulations! You have finished the PostgreSQL Docker installation on Ubuntu Linux.

Docker PostgreSQL – Persistent data

Create a docker volume for persistent data.

Copy to Clipboard

Verify the persistent data directory.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

Start a PostgreSQL container with persistent data storage.

Copy to Clipboard

In our example, the PostgreSQL password configured was kamisama123.

Verify the content of the persistent data directory.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

Congratulations! You successfully configured the use of Docker persistent data storage.

Tutorial PostgreSQL – Testing the Docker installation

Install the PostgreSQL client package on the localhost.

Copy to Clipboard

Access the PostgreSQL service running on the Docker container.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

Congratulations! Your PostgreSQL Docker installation was tested successfully.

Tutorial PostgreSQL – Docker container management

Verify the status of all Docker conteiners using the following command:

Copy to Clipboard

Here is the command output:

Copy to Clipboard

Verify the status of the PostgreSQL container using the ID or its name.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

To stop the PostgreSQL container service, use the following command:

Copy to Clipboard

To start the PostgreSQL container service, use the following command:

Copy to Clipboard

To restart the PostgreSQL container service, use the following command:

Copy to Clipboard

In case of error, use the following command to verify the PostgreSQL container logs.

Copy to Clipboard

In our examples, we demonstrated how to manage the PostgreSQL container using its ID or the name previously defined.