PostgreSQL Docker-based multi-instance installation

Source: Internet
Author: User
Tags postgresql psql docker hub docker run

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

    1. 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

    1. Installation
sudo apt-get updatesudoinstall docker-engine
    1. Open service
sudo service docker start
    1. 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

    1. Download the latest official Postgesql image
sudo Docker pull Postgres
    1. 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
    1. 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",

    1. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.