How to install and persist the postgresql database in docker

How to install and persist the postgresql database in docker

Skip the Docker installation steps

1. Pull the postgresql image

docker pull postgresql

2. Create a local volume. The data volume can be shared and reused between containers. By default, it will always exist even if the container is deleted ( docker volume inspect pgdata can view the local location of the data volume)

docker volume create pgdata

3. Start the container

docker run --name postgres2 -e POSTGRES_PASSWORD=password -p
5432:5432 -v pgdata:/var/lib/postgresql/data -d postgres 

4. Enter the postgres container and execute SQL

docker exec -it postgres2 bash
psql -h localhost -p 5432 -U postgres --password 

At this point, postgresql is installed successfully.

Supplement: Let's see how to install postgresql in docker

Pull the image

docker pull postgres:9.6

Start the container

Create the /usr/postgresql/data folder for persistence

docker run --name postgres -e
POSTGRES_PASSWORD=password -p 
5432:5432 -v /usr/postgresql/data:/var/lib/postgresql/data -d postgres

Enter postgresql

# Enter the container docker exec -it postgres /bin/bash
# Enter the folder cd /usr/lib/postgresql/9.6/bin
# Enter postgresql, the default postgres user psql -Upostgres

This is the end of this article about the steps to install and persist the postgresql database in docker. For more information about installing the postgresql database in docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • About Docker deployment postgresql database
  • Running PostgreSQL in Docker and recommending several connection tools
  • Solution for creating multiple databases when Docker starts PostgreSQL
  • How to install Postgres 12 + pgadmin in local Docker (support Apple M1)
  • Detailed steps to upgrade PostgreSQL in Docker environment
  • How to run postgreSQL with docker
  • Database backup in docker environment (postgresql, mysql) example code
  • How to deploy docker to access postgres database

<<:  Detailed explanation of the basic usage of VUE watch listener

>>:  Markup Language - List

Recommend

Web page html special symbols html special characters comparison table

Special symbols Named Entities Decimal encoding S...

A complete list of common Linux system commands for beginners

Learning Linux commands is the biggest obstacle f...

Even a novice can understand the difference between typeof and instanceof in js

Table of contents 1. typeof 2. instanceof 3. Diff...

Several specific methods of Mysql space cleaning

Table of contents Preface 1. Check the file disk ...

Analysis of the principle and usage of MySQL continuous aggregation

This article uses examples to illustrate the prin...

Use nginx to configure domain name-based virtual hosts

1. What is a virtual host? Virtual hosts use spec...

IIS7 IIS8 reverse proxy rule writing, installation and configuration method

Purpose: Treat Station A as the secondary directo...

JavaScript implements double-ended queue

This article example shares the specific code of ...

Basic knowledge of HTML: a preliminary understanding of web pages

HTML is the abbreviation of Hypertext Markup Langu...

Ideas and codes for realizing magnifying glass effect in js

This article example shares the specific code of ...

How to show or hide common icons on the desktop in Windows Server 2012

Windows Server 2012 and Windows Server 2008 diffe...