Docker Postgresql installation quickly
Task introduction
1.Docker
1.1. Docker Installation
2. Find the mirror
3. Download the mirror
4. View the mirror
5. Create a container and run it through mirroring
6. Delete the container and create a data directory for host mapping postgres
7. Check the status of the postgres container
8, enter the postgres container
9. Connection test outside the container-Complete port mapping so that external machines can access the database in the virtual machine
10. Other linking methods
1.Docker:
Docker is a cloud open source project. Powerful, scalable and lightweight container solutions are provided by Docker. The main goal of Docker is “Build, Ship and Run Any App, Anywhere”.
The Linux Container (LXC) technology is the base of the Docker engine. Docker further optimizes the use experience of containers on the basis of LXC and, at the same time, offers different container management resources (such as distribution, version, migration, etc.) so that users do not have to pay attention to the underlying operations.
1.1 Docker Installation
The company plans to use Docker to deploy projects in the near future, take the opportunity to learn more.
My Laptop configuration is Core i5, single core, 8g storage, 100g hard drive
Docker allows the Centos framework kernel version to be greater than 3.10, so first verify that the docker can be installed on your computer.
Execute on the computer the following commands:
[root@02a854a7db8d /]# uname -r
3.10.0–862.14.4.el7.x86_64
[root@02a854a7db8d /]#Use root login, or provide an account with sudo permissions, it should be possibleUpdate yum first[root@pankajconnect ~]# yum update -y
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.njupt.edu.cn
* updates: mirrors.aliyun.com
Resolving Dependencies
→ Running transaction checkWhere -y stands for automatic reply yes to prevent this
After a bunch of cool linux information screens, you can officially start installing docker
[root@pankajconnect ~]# yum install docker -y
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.njupt.edu.cn
* updates: mirrors.aliyun.com
Resolving Dependencies
— — — -
Note:
Docker adopts the timeline method as the version number since version 1.13, divided into community version CE and enterprise version EE.
The community version is free for individual developers and small groups to use, and the enterprise version will provide additional paid services, such as infrastructure, containers, and plug-ins that have been officially tested and certified.
The community version is released in two ways: stable and edge. The stable version is updated quarterly, such as 17.06, 17.09; the edge version is updated every month, such as 17.09, 17.10.
My current installation method is not the latest installation method, but the last version before the Docker distribution. Can use:
Next start dockersystemctl status docker.serviceafter finishing[root@pankajconnect Desktop]# docker search postgres--Continue as below....
2. Find the mirror
[root@pankajconnect ~]# docker search postgres
3. Download the mirror
4. View the mirror
5. Create a container and run it through mirroring
[root@pankajconnect ~]# docker run — name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data -l logfile start
6. Delete the container and create a data directory for host mapping postgres
[root@pankajconnect ~]# docker ps -a
[root@pankajconnect ~]# docker rm e63b736f0f3f
Create a data directory for host mapping postgres
[root@pankajconnect data]# run, Create and run a container;,
— namespecify the name of the created container -e POSTGRES_PASSWORD=password;, set environment variables, specify the database login password as password;, -p 5432:5432port mapping will map the container’s 5432 port to the external machine’s 54321 port;
7. Check the status of the postgresql container
[root@pankajconnect data]# docker ps -a
8, enter the postgres container
[root@pankajconnect data]# docker exec -it postgres /bin/bash
root@aec8a31d2ae1:/# ls
postgres=# show port;
port
— — —
5432
(1 row)
postgres=# show config_file ;
config_file
— — — — — — — — — — — — — — — — — — — — —
/var/lib/postgresql/data/postgresql.conf
(1 row)
postgres=# \q
postgres@aec8a31d2ae1:~$
9. Connection test outside the container-Complete port mapping so that external machines can access the database in the virtual machine
Error: No psql client installed
[root@pankajconnect ~]# yum install postgresql
Note :
Postgres mirroring default user name postgres,
login password for the creation of a container is the specified value.
[root@pankajconnect ~]# [root@pankajconnect ~]# psql -h 192.168.40.105 -p 5432 -d postgres -U postgres
10. Other linking methods
In fact, the container also has its own IP address in /var/lib/docker/containers/container ID/hosts
I like to learn new and better ways of doing things when working on a scale, and feel free to ask questions and make suggestions.
Also, check out another story on this.
Thanks for reading this.