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

WeChat Mini Programs are shared globally via uni-app

In actual use, it is often necessary to share the...

Javascript to achieve drumming effect

This article shares the specific code of Javascri...

Essential skills for designing web front-end interfaces

[Required] UserInterface PhotoShop/Fireworks Desi...

Drop-down menu and sliding menu design examples

I found a lot of websites that use drop-down or sl...

Nginx proxy forwarding implementation code uploaded by Alibaba Cloud OSS

Preface Because the mini program upload requires ...

Mysql keeps the existing content and adds content later

This command modifies the data table ff_vod and a...

js version to realize calculator function

This article example shares the specific code of ...

Graphical tutorial on installing CentOS 7.3 on VMWare

Illustrated CentOS 7.3 installation steps for you...

Four modes of Oracle opening and closing

>1 Start the database In the cmd command windo...

VMware, nmap, burpsuite installation tutorial

Table of contents VMware BurpSuite 1. Virtual mac...

Detailed explanation of CSS3 rotating cube problem

3D coordinate concept When an element rotates, it...

React example of how to get the value of the input box

React multiple ways to get the value of the input...

JavaScript regular verification password strength implementation method

exhibit design Password strength analysis The pas...