docker安装postgres 15.1

docker拉取镜像:

docker pull postgres:15.1 

创建文件夹,以及启动images

创建文件夹:mkdir -p /opt/docker/postgres
docker run --name postgres \
    -e POSTGRES_PASSWORD=password \
    -p 5432:5432 \
    -v /opt/docker/postgres:/var/lib/postgresql/data \
    -d postgres:latest 
    
    持久化创建docker容器
    docker run --name postgres \
    --restart=always \
    -e POSTGRES_PASSWORD=password \
    -p 5432:5432 \
    -v /data/postgresql:/var/lib/postgresql/data \
    -d postgres:15.1
    un: 创建并运行一个容器;

 --restart=always 表示容器退出时,docker会总是自动重启这个容器;
–name: 指定创建的容器的名字;
-e POSTGRES_PASSWORD=password: 设置环境变量,指定数据库的登录口令为password;
-p 5432:5432: 端口映射将容器的5432端口映射到外部机器的5432端口;

-v  /data/postgresql:/var/lib/postgresql/data   将运行镜像的/var/lib/postgresql/data目录挂载到宿主机/data/postgresql目录
-d postgres:11.4: 指定使用postgres:11.4作为镜像。

启动容器查看启动日志:

[root@128 postgres]# docker ps
CONTAINER ID   IMAGE                COMMAND                  CREATED         STATUS         PORTS                                                  NAMES
d1719ff15b21   postgres:latest      "docker-entrypoint.s…"   6 minutes ago   Up 6 minutes   0.0.0.0:5432->5432/tcp, :::5432->5432/tcp              postgres
b4e746e59cfc   mysql:8.0            "docker-entrypoint.s…"   17 hours ago    Up 17 hours    33060/tcp, 0.0.0.0:3103->3306/tcp, :::3103->3306/tcp   slaver1
59d0ba2f9ba1   mysql:8.0            "docker-entrypoint.s…"   17 hours ago    Up 17 hours    33060/tcp, 0.0.0.0:3102->3306/tcp, :::3102->3306/tcp   slaver
fce67889be45   mysql:8.0            "docker-entrypoint.s…"   17 hours ago    Up 17 hours    33060/tcp, 0.0.0.0:3101->3306/tcp, :::3101->3306/tcp   master
fbbcd73697a1   nacos/nacos-server   "bin/docker-startup.…"   18 hours ago    Up 17 hours    0.0.0.0:8841->8848/tcp, :::8841->8848/tcp              nacos-8841
[root@128 postgres]# docker stop fbbcd73697a1
fbbcd73697a1
[root@128 postgres]# docker logs -f d1719ff15b21
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /var/lib/postgresql/data -l logfile start

waiting for server to start....2022-12-23 02:22:12.495 UTC [47] LOG:  starting PostgreSQL 15.1 (Debian 15.1-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-12-23 02:22:12.496 UTC [47] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-12-23 02:22:12.523 UTC [50] LOG:  database system was shut down at 2022-12-23 02:22:12 UTC
2022-12-23 02:22:12.541 UTC [47] LOG:  database system is ready to accept connections
 done
server started

/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*

waiting for server to shut down...2022-12-23 02:22:13.857 UTC [47] LOG:  received fast shutdown request
.2022-12-23 02:22:13.913 UTC [47] LOG:  aborting any active transactions
2022-12-23 02:22:13.917 UTC [47] LOG:  background worker "logical replication launcher" (PID 53) exited with exit code 1
2022-12-23 02:22:13.917 UTC [48] LOG:  shutting down
2022-12-23 02:22:13.919 UTC [48] LOG:  checkpoint starting: shutdown immediate
2022-12-23 02:22:13.925 UTC [48] LOG:  checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.001 s, sync=0.001 s, total=0.006 s; sync files=2, longest=0.001 s, average=0.001 s; distance=0 kB, estimate=0 kB
2022-12-23 02:22:13.930 UTC [47] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

2022-12-23 02:22:14.000 UTC [1] LOG:  starting PostgreSQL 15.1 (Debian 15.1-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-12-23 02:22:14.050 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2022-12-23 02:22:14.050 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2022-12-23 02:22:14.051 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-12-23 02:22:14.057 UTC [60] LOG:  database system was shut down at 2022-12-23 02:22:13 UTC
2022-12-23 02:22:14.061 UTC [1] LOG:  database system is ready to accept connections
2022-12-23 02:27:14.127 UTC [58] LOG:  checkpoint starting: time
2022-12-23 02:28:52.266 UTC [58] LOG:  checkpoint complete: wrote 919 buffers (5.6%); 0 WAL file(s) added, 0 removed, 0 recycled; write=98.123 s, sync=0.002 s, total=98.140 s; sync files=251, longest=0.001 s, average=0.001 s; distance=4217 kB, estimate=4217 kB

防火墙中添加端口

firewall-cmd --zone=public --add-port=5432/tcp --permanent
重新载入
firewall-cmd --reload

客户端连接:密码在创建的命令中,查看ip可以使用 IP add 命令来查看

猜你喜欢

转载自blog.csdn.net/qq_40408317/article/details/128416997