Reference: https://hub.docker.com/_/postgres/
https://docs.docker.com/engine/installation/debian/
Using Docker for multi-instance installation is simpler, more convenient, and better isolated than the source code.
Installing Docker
- Update the installation source
sudo apt-key adv--keyserver HKP://p80.pool.sks-keyservers.net:80--recv-keys 58118e89f3a912897c070adbf76221572c52609dsudotouch /etc/apt/sources.list.d/ Docker.listsudo vim/etc/apt/sources.list.d/docker.list
Write based on system:
Deb Https://apt.dockerproject.org/repo Debian-jessie Main
- Installation
sudo apt-get updatesudoinstall docker-engine
- Open service
sudo service docker start
- Verify
sudoDocker Run hello-World the command downloads a test image, runs inside the container, prints out the relevant information, and looks like the following message is working. Hello from Docker.this message shows this your installation appears to be working correctly. To generate this message, Docker took the following steps:1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the"Hello-world"image from the Docker Hub.3. The Docker daemon created a new container from that imagewhichruns the executable that produces the output is currently reading.4. The Docker daemon streamed that output to the Docker client,whichsent ITTO your terminal.
Installing PostgreSQL
- Download the latest official Postgesql image
sudo Docker pull Postgres
- Start two mirrors and map to host 5454 and Port 5455, respectively
sudo 5454:5432 -E postgres_password=postgres-d POSTGRESsudo5455:5432 -E postgres_password=postgres-d POSTGRES
- View the containers in operation and related information
[Email protected]:~$sudoDockerPSCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS Names3bf3b533ba05 Postgres"/docker-entrypoint.s" -Seconds ago Up -Seconds0.0.0.0:5455-5432/TCP Cluster229b9ffeb6ac8 Postgres"/docker-entrypoint.s" -Seconds ago Up AboutSeconds0.0.0.0:5454-5432/TCP Cluster1[email protected]:~$sudoDocker Inspect 3BF3B533BA05 |grepIPAddress"secondaryipaddresses":NULL, "IPAddress":"172.17.0.3", "IPAddress":"172.17.0.3", [email protected]:~$sudoDocker Inspect 29b9ffeb6ac8 |grepIPAddress"secondaryipaddresses":NULL, "IPAddress":"172.17.0.2", "IPAddress":"172.17.0.2",
- Test the connection according to the IPAddress in the previous step
[Email protected]:~$ psql-h172.17.0.2-upostgres-P5432password forUser Postgres:psql (9.5.0) Type" Help" forHelp . Postgres=# \l List of Databases Name| Owner | Encoding | Collate | Ctype |Access Privileges-----------+----------+----------+------------+------------+-----------------------Postgres| Postgres | UTF8 | En_us.utf8 | En_us.utf8 |Template0| Postgres | UTF8 | En_us.utf8 | En_us.utf8 | =c/postgres + | | | | | postgres=ctc/Postgres template1| Postgres | UTF8 | En_us.utf8 | En_us.utf8 | =c/postgres + | | | | | postgres=ctc/Postgres (3rows) [Email protected]:~$ psql-h172.17.0.3-upostgres-P5432password forUser Postgres:psql (9.5.0) Type" Help" forHelp . Postgres=# \l List of Databases Name| Owner | Encoding | Collate | Ctype |Access Privileges-----------+----------+----------+------------+------------+-----------------------Postgres| Postgres | UTF8 | En_us.utf8 | En_us.utf8 |Template0| Postgres | UTF8 | En_us.utf8 | En_us.utf8 | =c/postgres + | | | | | postgres=ctc/Postgres template1| Postgres | UTF8 | En_us.utf8 | En_us.utf8 | =c/postgres + | | | | | postgres=ctc/Postgres (3rows) connect to database via host address and port [email protected]:~$ psql-h192.168.10.131-p5454-Upostgrespassword forUser Postgres:psql (9.5.0) Type" Help" forHelp . Postgres=# \l List of Databases Name| Owner | Encoding | Collate | Ctype |Access Privileges-----------+----------+----------+------------+------------+-----------------------Postgres| Postgres | UTF8 | En_us.utf8 | En_us.utf8 |Template0| Postgres | UTF8 | En_us.utf8 | En_us.utf8 | =c/postgres + | | | | | postgres=ctc/Postgres template1| Postgres | UTF8 | En_us.utf8 | En_us.utf8 | =c/postgres + | | | | | postgres=ctc/Postgres (3rows) Postgres=# \q[email protected]:~$ psql-h192.168.10.131-p5455-Upostgrespassword forUser Postgres:psql (9.5.0) Type" Help" forHelp . Postgres=# \l List of Databases Name| Owner | Encoding | Collate | Ctype |Access Privileges-----------+----------+----------+------------+------------+-----------------------Postgres| Postgres | UTF8 | En_us.utf8 | En_us.utf8 |Template0| Postgres | UTF8 | En_us.utf8 | En_us.utf8 | =c/postgres + | | | | | postgres=ctc/Postgres template1| Postgres | UTF8 | En_us.utf8 | En_us.utf8 | =c/postgres + | | | | | postgres=ctc/Postgres (3Rows
View data files, configuration files, network authorization file settings in a container
sudo docker exec-it 3bf3b533ba05/bin/bash all PostgreSQL configuration files and data data files are located at:/var/lib/postgresql/data
PostgreSQL Docker-based multi-instance installation