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

I need to build docker image with postgres with data included

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

我的步数:

  1. docker-compose build //创建ps_image_with_data
  2. docker run --name ps-export -p 5432:5432 -i postgres
  3. 连接到 5432 db,使用 dbeaver;创建 table;在 table
  4. 中放置一些行
  5. docker exec -it my_container_with_data_id bash
  6. mkdir /postgres
  7. cp -r /var/lib/postgresql/data/* /postgres
  8. docker commit ps-export ps_image_with_data
  9. 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] LOG: listening on IPv4 address "0.0.0.0", port 5432 2018-11-08 12:44:52.549 UTC [1] LOG: listening on IPv6 address "::", port 5432 2018-11-08 12:44:52.615 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" 2018-11-08 12:44:52.750 UTC [22] LOG: database system was interrupted; last known up at 2018-11-08 11:56:27 UTC 2018-11-08 12:45:25.042 UTC [22] LOG: could not remove cache file "global/pg_internal.init": Permission denied 2018-11-08 12:45:25.042 UTC [22] LOG: could not remove cache file "base/13067/pg_internal.init": Permission denied 2018-11-08 12:45:25.042 UTC [22] LOG: database system was not properly shut down; automatic recovery in progress 2018-11-08 12:45:25.127 UTC [22] LOG: redo starts at 0/166CF68 2018-11-08 12:45:25.127 UTC [22] LOG: invalid record length at 0/166D048: wanted 24, got 0 2018-11-08 12:45:25.127 UTC [22] LOG: redo done at 0/166D010 2018-11-08 12:45:25.259 UTC [22] PANIC: could not rename file "pg_logical/replorigin_checkpoint.tmp" to "pg_logical/replorigin_checkpoint": Permission denied 2018-11-08 12:45:25.357 UTC [1] LOG: startup process (PID 22) was terminated by signal 6: Aborted 2018-11-08 12:45:25.358 UTC [1] LOG: aborting startup due to startup process failure 2018-11-08 12:45:25.359 UTC [1] LOG: database system is shut down

谁能帮我解决一下?

怎么样

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

  2. 连接到 5432 db,使用 dbeaver;创建 table;在 table

  3. 中放置一些行
  4. 转储 (data.sql) 到您的主机

  5. 在你的docker-compose.yml下添加psql server

`

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

如果您想在图像中包含 data.sql,而不是第 4 步,请将其复制到 docker 文件中的 /docker-entrypoint-initdb.d/init.sql