我需要用包含数据的postgres构建docker镜像



所以,我需要docker镜像:我的程序使用postgresql、postgresql和其中的一些数据我使用这篇文章:https://medium.com/@sharmaNK/build-postgres-docker-image-包含数据-489bd58a1f9e

我的步骤:

  1. docker-compose build//创建ps_image_with_data
  2. docker run --name ps-export -p 5432:5432 -i postgres
  3. 使用dbeaver连接到5432 db;创建表格;在表中放几行
  4. docker exec -it my_container_with_data_id bash
  5. mkdir /postgres
  6. cp -r /var/lib/postgresql/data/* /postgres
  7. docker commit ps-export ps_image_with_data
  8. docker run --env PGDATA=postgres -p 5432:5432 -i ps_image_with_data//这里我已经尝试了ps_image_with_data和在步骤7中创建的新图像

经过8步后,我得到了这个:

2018-11-08 12:44:52.549 UTC[1]日志:正在侦听IPv4地址"0.0.0.0",端口5432 2018-11-08 12:44:52.549 UTC[1]日志:正在侦听在IPv6地址"::"上,端口5432 2018-11-08 12:44:52.615 UTC[1]日志:监听Unix套接字"/var/run/postgresql/.s.PGSQL.5432"2018-11-08 12:44:52.750 UTC[22]日志:数据库系统被中断;最后一次出现在2018-11-08 11:56:27 UTC 2018-11-0812:45:25.042 UTC[22]日志:无法删除缓存文件"global/pg_internal.init":权限被拒绝2018-11-08 12:45:25.042UTC[22]日志:无法删除缓存文件"base/13067/pg_internal.init":权限被拒绝2018-11-0812:45:25.042 UTC[22]日志:数据库系统未正确关闭向下自动恢复正在进行中2018-11-08 12:45:25.127 UTC[22]日志:重做开始于0/166CF68 2018-11-08 12:45:25.127 UTC[22]日志:0/166D048处的记录长度无效:需要24,得到0 2018-11-0812:45:25.27 UTC[22]日志:重做完成时间:0/166D010 2018-11-0812:45:25.259 UTC[22]PANIC:无法重命名文件"pg_logical/replorigin_checkpoint.tmp"到"pg_logical/replorigin_checkpoint":权限被拒绝2018-11-0812:45:25.357 UTC[1]日志:启动进程(PID 22(由终止信号6:中止2018-11-08 12:45:25.358 UTC[1]日志:中止由于启动过程失败而启动2018-11-08 12:45:25.359 UTC[1]日志:数据库系统关闭

有人能帮我解决吗?

怎么样

  1. docker run--name ps export-p 5432:5432-i postgres

  2. 使用dbeaver连接到5432 db;创建表格;在表中放入一些行

  3. 向主机转储(data.sql(

  4. 添加到您的docker-compose.yml中,在psql服务器下

`

volumes:
- ./data.sql:/docker-entrypoint-initdb.d/init.sql
  1. docker-compose up

如果要在映像中包括data.sql,而不是步骤4,请将其复制到dockerfile中的/docker-entrypoint-initdb.d/init.sql

最新更新