docker 安装 postgres 15.1
docker拉取镜像:
docker pull postgres:15.1
创建文件夹,以及启动images
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 创建文件夹: 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作为镜像。 |
启动容器查看启动日志:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | [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 |
防火墙中添加端口:
1 2 3 | firewall-cmd --zone=public --add-port=5432 /tcp --permanent 重新载入 firewall-cmd --reload |
客户端连接:密码在创建的命令中,查看ip可以使用 IP add 命令来查看
本文来自博客园,作者:diligently,转载请注明原文链接:https://www.cnblogs.com/luo12828-foxmail/p/17000238.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了