Installing PostgreSQL with container image

You can install PostgresSQL via container image. The location and name of PostgreSQL container image varies in your operating system architecture. You must choose the right image according to your environment.

About this task

The following installing procedure takes xLinux container as an example.

Procedure

  1. Download PostgreSQL database image from registry through command docker pull postgres. For example,
    docker pull postgres:16
  2. Create one directory in your host machine to save all database related data through the following commands:
    mkdir -p /var/lib/postgresql/data
  3. Create and run new PostgreSQL container from the downloaded image through the following command:
    docker run -d --name yourcontainerName -p your port in host:5432 -e POSTGRES_PASSWORD=your password -e 
    PGDATA=/var/lib/postgresql/data/pgdata -v your created directory: =/var/lib/postgresql/data postgres:16
    For example,
    docker run -d --name chatops-postgres -p 5432:5432 -e POSTGRES_PASSWORD=abcdefg -e PGDATA=/var/lib/postgresql/data/pgdata -v /var/lib/postgresql/data:/var/lib/postgresql/data postgres:16

What to do next

If you want to manage PostgreSQL through pgAdmin 4, install pgAdmin 4. For more information, see Installing pgAdmin 4.