How to run postgreSQL with docker

How to run postgreSQL with docker

1. Install Docker.
Reference URL:

Docker Getting Started Installation Tutorial (Beginner Edition)

Install Docker on Linux (very simple installation method)

2. Pull the docker image file of postgreSQL: docker pull postgres:12.1

3. Create a docker volume named "dv_pgdata" (you can skip the manual creation and run the next step directly, docker will automatically create it): docker volume create dv_pgdata

4. Start the container and use -v to specify that the postgres data directory is mapped to the dv_pgdata created above: docker run --name my_postgres -v dv_pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=xxxxxx -p 5432:5432 -d postgres:12.1

5. Now check the existing docker volume: docker volume ls

6. View volume information:

[root@VM_0_6_centos _data]# docker inspect dv_pgdata
[
  {
    "CreatedAt": "2020-01-14T08:40:03+08:00",
    "Driver": "local",
    "Labels": {},
    "Mountpoint": "/var/lib/docker/volumes/dv_pgdata/_data",
    "Name": "dv_pgdata",
    "Options": {},
    "Scope": "local"
  }
]

7. On the host machine, you can also directly view the contents of the volume:

[root@VM_0_6_centos _data]# cd /var/lib/docker/volumes/dv_pgdata/_data
[root@VM_0_6_centos _data]# ll
total 132
drwx------ 19 polkitd ssh_keys 4096 Jan 14 08:40 .
drwxr-xr-x 3 root root 4096 Jan 14 08:33 ..
drwx------ 5 polkitd ssh_keys 4096 Jan 14 08:38 base
drwx------ 2 polkitd ssh_keys 4096 Jan 14 08:38 global
drwx------ 2 polkitd ssh_keys 4096 Jan 14 08:38 pg_commit_ts
drwx------ 2 polkitd ssh_keys 4096 Jan 14 08:38 pg_dynshmem
-rw------ 1 polkitd ssh_keys 4535 Jan 14 08:38 pg_hba.conf
-rw------ 1 polkitd ssh_keys 1636 Jan 14 08:38 pg_ident.conf
drwx------ 4 polkitd ssh_keys 4096 Jan 14 08:45 pg_logical
drwx------ 4 polkitd ssh_keys 4096 Jan 14 08:38 pg_multixact
drwx------ 2 polkitd ssh_keys 4096 Jan 14 08:40 pg_notify
drwx------ 2 polkitd ssh_keys 4096 Jan 14 08:38 pg_replslot
drwx------ 2 polkitd ssh_keys 4096 Jan 14 08:38 pg_serial
drwx------ 2 polkitd ssh_keys 4096 Jan 14 08:38 pg_snapshots
drwx------ 2 polkitd ssh_keys 4096 Jan 14 08:40 pg_stat
drwx------ 2 polkitd ssh_keys 4096 Jan 14 16:44 pg_stat_tmp
drwx------ 2 polkitd ssh_keys 4096 Jan 14 08:38 pg_subtrans
drwx------ 2 polkitd ssh_keys 4096 Jan 14 08:38 pg_tblspc
drwx------ 2 polkitd ssh_keys 4096 Jan 14 08:38 pg_twophase
-rw------ 1 polkitd ssh_keys 3 Jan 14 08:38 PG_VERSION
drwx------ 3 polkitd ssh_keys 4096 Jan 14 08:38 pg_wal
drwx------ 2 polkitd ssh_keys 4096 Jan 14 08:38 pg_xact
-rw------ 1 polkitd ssh_keys 88 Jan 14 08:38 postgresql.auto.conf
-rw------ 1 polkitd ssh_keys 26588 Jan 14 08:38 postgresql.conf
-rw------ 1 polkitd ssh_keys 36 Jan 14 08:40 postmaster.opts
-rw------ 1 polkitd ssh_keys 94 Jan 14 08:40 postmaster.pid

8. View postgresql:

[root@VM_0_6_centos ~]#docker exec -it 618 bash
root@618f1a4128ee:/# psql -U postgres

psql (12.1 (Debian 12.1-1.pgdg100+1))
Type "help" for help.

postgres=#

9. More often, we hope to use a graphical interface to manage and operate the database. We can deploy the pgadmin tool (for example, as shown below), and then access port 5080 of the host machine in the browser to open pgadmin.

docker pull dpage/pgadmin4:4.17
docker run --name pgadmin -p 5080:80 \
  -e '[email protected]' \
  -e 'PGADMIN_DEFAULT_PASSWORD=xxxxxx' \
  -e 'PGADMIN_CONFIG_ENHANCED_COOKIE_PROTECTION=True' \
  -e 'PGADMIN_CONFIG_LOGIN_BANNER="Authorised users only!"' \
  -e 'PGADMIN_CONFIG_CONSOLE_LOG_LEVEL=10' \
  -d dpage/pgadmin4:4.17

This is the end of this article about the steps to run postgreSQL with docker. For more information about running postgreSQL with 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 install and persist the postgresql database in docker
  • Database backup in docker environment (postgresql, mysql) example code
  • How to deploy docker to access postgres database

<<:  MySQL database implements OLTP benchmark test based on sysbench

>>:  JavaScript article will show you how to play with web forms

Recommend

Mybatis paging plug-in pageHelper detailed explanation and simple example

Mybatis paging plug-in pageHelper detailed explan...

How to clear the validation prompt in element form validation

Table of contents Problem scenario: Solution: 1. ...

Use of Linux ipcs command

1. Command Introduction The ipcs command is used ...

How to implement https with nginx and openssl

If the server data is not encrypted and authentic...

How to set a fixed IP address in CentOS7 virtual machine

Since my development environment is to install Ce...

mysql IS NULL using index case explanation

Introduction The use of is null, is not null, and...

Usage and description of HTML tag tbody

The tbody element should be used in conjunction wi...

Analyze how uniapp dynamically obtains the interface domain name

background The interface domain name is not hard-...

HTML tutorial, easy to learn HTML language

1. <body background=image file name bgcolor=co...

Detailed instructions for installing Jenkins on Ubuntu 16.04

1. Prerequisites JDK has been installed echo $PAT...

Linux uses join -a1 to merge two files

To merge the following two files, merge them toge...

Detailed explanation of asynchronous iterators in nodejs

Table of contents Preface What are asynchronous i...