Docker: Docker deployment postgresql database

surroundings

Centos-7 

Postgresql-10

docker-19

 

yum load Postgresql

yum  install https: // download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm -and  

 

View Postgresql version

yum list | grep postgresql

 

Download Postgresql Mirror

# Pull obtain a version 10 
Docker pull Postgres: 10

 

Create a host mapping sql directory

# Here I var / lib / created under
 mkdir / var / lib / PostgreSqlData

 

Construction of Mirror

Mirror # Name modification (docker tag ID mirrored the custom name) 
Docker --name Postgres RUN ~ -v / var / lib / PostgreSqlData: / Home / Data / -e -d -p POSTGRES_PASSWORD ****** ** = **: 5432 Postgres

--name: is a mirror name

-v: mapping, local directory: the container path

POSTGRES_PASSWORD: Database Password

-p: port mapping, the host port: the port of the container

Finally, the custom container name

 

Here's a simple command

docker run -d --name postgresql2 --restart always -e POSTGRES_USER=abcuser -e POSTGRES_PASS='abc123' -e ALLOW_IP_RANGE=0.0.0.0/0 -v /docker_root/postgresql11-docker:/var/lib/postgresql -v /4T/tmp:/tmp/tmp -p 55433:5432 -t postgis
  • -e ALLOW_IP_RANGE = 0.0.0.0 / 0, this representation allows all ip access, if not, it can not access the non-native ip
  • -e POSTGRES_USER = abcuser Username
  • -e POSTGRES_PASS = 'abc123' specify a password

 

Postgres into the container

docker exec -it container ID bash

 

Update software source

# Source list update software 
APT - GET Update 

# install vim 
APT -get -y install vim

 

 

Configure Remote Access

# Change to the directory / var / lib / PostgreSQL / Data 
CD / var / lib / PostgreSQL / Data

 Edit postgresql.conf file

# Review: listening on all IP addresses, allowing remote connection to the database server: 
listening_address: ' * '

Edit pg_hba.conf file

# Add or edit: allow any user access to the password database from any machine, the first rule is added to the downlink: 
Host All All              0.0 . 0.0 / 0                MD5

 

Modify the encoding format

update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = 'basemap'

 

View pg version

the server_version Show; 
# or 
SELECT Version ();

 

Restart container

docker restart vessel name

 

carry out! 

 

Recommended github path: postgres + postgis deploy multiple versions of a file set DockerFile: https://github.com/postgis/docker-postgis

Guess you like

Origin www.cnblogs.com/nhdlb/p/12517610.html