node.js - 如何使用在 docker 中运行的 Node 在微服务架构中初始化 postgres 数据库表

标签 node.js postgresql docker containers microservices

在 postgres 数据库中初始化 Node 微服务表的最佳实践是什么?它应该在服务启动时吗?

我正在考虑将所有 .sql 文件复制到容器(在 docker 构建期间)+ 将 psql 安装到该容器中,并且仅在 npm 启动之前在 docker run 期间运行 .sql 文件。这有意义吗?

我需要考虑的事实是,很快我还需要为微服务管理升级数据库的表。

最佳答案

一种可能是 Docker Postgres 镜像推荐的:

How to extend this image

If you would like to do additional initialization in an image derived from this one, add one or more *.sql or *.sh scripts under /docker-entrypoint-initdb.d (creating the directory if necessary).

After the entrypoint calls initdb to create the default postgres user and database, it will run any *.sql files and source any *.sh scripts found in that directory to do further initialization before starting the service.

关于node.js - 如何使用在 docker 中运行的 Node 在微服务架构中初始化 postgres 数据库表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37243939/

相关文章:

qt - PostgreSQL 和 QSqlQuery.bindValue() 很慢

docker - 通过docker、kubernetes和google云平台部署应用的步骤

JavaScript 数组 : string indexed items

node.js - Node JS 中是否也需要每个 React 库?

python - Django 和 Postgresql 运算符不存在 : integer = character varying

java - 使用 Java exec 的额外 psql 命令行参数

javascript - 无法读取未定义的属性 'currentUser'

python - 从python脚本获取输出到django

linux - Docker DNS 设置

windows - 使用 Docker 在 Windows 上安装 gitlab