节点npmtesting种子postgres,Dockernetworking容器看到不同的结果

我正在对种子postgres数据库运行Angular Node npmtesting。 这在一个环境中工作,但不是另一个。

我已经将图像导出并将其从一个环境移动到另一个环境,结果表明环境而不是泊坞窗图像有所不同。 我也有一切检查到混帐,并完成了图像的清洁版本。

pg = $(docker run -d postgres-seeded)
docker run -it –net = container:$ pg nodeapp npm test

这是我见过的作品的matrix,而不是作品

machine | npm test result mac os X - docker 1.10.3 | success | webstorm local to docker to post-| gres-seeded - mac os X docker | success | amazon ami on AWS docker 1.9.1 | error below amazon ami on AWS docker 1.10.3 | error below ubuntu 14.04 on AWS docker 1.10.3| success on one instance, error below 

失败时的错误是无法连接到postgres

  4) AccessPermissionsRoutes "before all" hook: Error: The genericPool is not initialized. at Pool_PG.Pool.acquire (/usr/src/app/node_modules/knex/lib/pool.js:57:14) at /usr/src/app/node_modules/knex/lib/client.js:33:10 at tryCatcher (/usr/src/app/node_modules/knex/node_modules/bluebird/js/main/util.js:26:23) at Promise._resolveFromResolver (/usr/src/app/node_modules/knex/node_modules/bluebird/js/main/promise.js:480:31) at new Promise (/usr/src/app/node_modules/knex/node_modules/bluebird/js/main/promise.js:70:37) at Client_PG.Client.acquireConnection (/usr/src/app/node_modules/knex/lib/client.js:31:10) 

我能解决这个问题。 这与Postgres播种后处于不稳定状态有关。 它不会一直发生,所以不知道它什么时候发生或没有发生。

所以解决方法是每次使用新的postgres映像,并使用卷容器对数据进行种子处理。

  seeded=$(docker run --name seeded_1-v /var/lib/postgresql/data -d busybox true) pg=$(docker run --volumes-from $seeded -d postgres) docker run -e DATABASE_URL=postgres://postgres@localhost:5432 --net=container:$pg seeding-image 

种子图像是您的自定义docker图像种子postgres数据库。

重新创build并重新设置Postgres容器,然后重试。 最有可能解决您在代码中看到的连接问题。