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

How to add sudo permissions to a user in Linux environment

sudo configuration file The default configuration...

How to use the yum command

1. Introduction to yum Yum (full name Yellow dogU...

VMware kali virtual machine environment configuration method

1|0 Compile the kernel (1) Run the uname -r comma...

Analysis of MySQL's method of exporting to Excel

This article describes how to use MySQL to export...

Instructions for nested use of MySQL ifnull

Nested use of MySQL ifnull I searched online to s...

Vue.js implements the code of clicking the icon to zoom in and leaving

The previous article introduced how Vue can reali...

jQuery custom magnifying glass effect

This article example shares the specific code of ...

How to use wangEditor in vue and how to get focus by echoing data

Rich text editors are often used when doing backg...

How to deploy gitlab using Docker-compose

Docker-compose deploys gitlab 1. Install Docker I...

My CSS framework - base.css (reset browser default style)

Copy code The code is as follows: @charset "...

How to remove carriage return characters from text in Linux

When the carriage return character ( Ctrl+M ) mak...