wb.ouyang

毕竟几人真得鹿,不知终日梦为鱼

导航

< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

统计

基于官方postgres docker镜像制作自己的镜像

1、Dockerfile

复制代码
FROM library/postgres
MAINTAINER wenbin.ouyang

#初始化PostgreSQL
ENV POSTGRES_USER root
ENV POSTGRES_PASSWORD root
ENV POSTGRES_DB noah
ADD ./noah_pgsql_init.sql /docker-entrypoint-initdb.d/

#容器运行时监听的端口
EXPOSE 5432
复制代码

  

2、构建镜像

docker build -f ./Dockerfile -t oy/pgsql:1.0.0 .

 

  docker images: 查看镜像

 

3、创建容器

  容器中postgresql的数据存放位置:/var/lib/postgresql/data,通过容器添加卷指令将容器数据存放位置映射到宿主机:-v /var/lib/postgresql/oy_PostgreSQL_1.0.0_data:/var/lib/postgresql/data

docker run -it -p 9001:5432 -v /var/lib/postgresql/oy_PostgreSQL_1.0.0_data:/var/lib/postgresql/data oy/pgsql:1.0.0

  docker ps: 查看运行的容器

  docker exec -it 容器id /bin/bash:进入到容器

 

  创建容器时的打印:

复制代码
root@alihkdev13:/usr/local/resource# docker run -it -p 9001:5432 -v /var/lib/postgresql/oy_PostgreSQL_1.0.0_data:/var/lib/postgresql/data oy/pgsql:1.0.0
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
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....2019-12-24 03:20:08.792 UTC [46] LOG:  starting PostgreSQL 12.1 (Debian 12.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2019-12-24 03:20:08.803 UTC [46] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2019-12-24 03:20:08.861 UTC [47] LOG:  database system was shut down at 2019-12-24 03:20:08 UTC
2019-12-24 03:20:08.881 UTC [46] LOG:  database system is ready to accept connections
 done
server started
CREATE DATABASE


/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/noah_pgsql_init.sql
psql:/docker-entrypoint-initdb.d/noah_pgsql_init.sql:1: NOTICE:  table "encryption" does not exist, skipping
DROP TABLE
CREATE TABLE
COMMENT
COMMENT
COMMENT
COMMENT
COMMENT
COMMENT
COMMENT

2019-12-24 03:20:09.409 UTC [46] LOG:  received fast shutdown request
waiting for server to shut down....2019-12-24 03:20:09.429 UTC [46] LOG:  aborting any active transactions
2019-12-24 03:20:09.430 UTC [46] LOG:  background worker "logical replication launcher" (PID 53) exited with exit code 1
2019-12-24 03:20:09.431 UTC [48] LOG:  shutting down
2019-12-24 03:20:09.526 UTC [46] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

2019-12-24 03:20:09.653 UTC [1] LOG:  starting PostgreSQL 12.1 (Debian 12.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2019-12-24 03:20:09.653 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2019-12-24 03:20:09.653 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2019-12-24 03:20:09.670 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2019-12-24 03:20:09.718 UTC [73] LOG:  database system was shut down at 2019-12-24 03:20:09 UTC
2019-12-24 03:20:09.737 UTC [1] LOG:  database system is ready to accept connections
复制代码

posted on   wenbin_ouyang  阅读(3629)  评论(2编辑  收藏  举报

编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示