Node npm test to seeded postgres, Docker network container seeing varying results
I am running an Angular Node npm test against a seeded postgres database. This works in one environment but not another.
I have exported the images to and moved them from one environment to the other, and the results indicate that there’s a difference with the environments and not the docker images. I also have everything checked into git, and have done clean builds of the images.
pg=$(docker run -d postgres-seeded)
docker run -it –net=container:$pg nodeapp npm test
Here’s the matrix of what I’ve seen works/ and not works
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
the error when it fails is not able to connect to 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)
2 Solutions collect form web for “Node npm test to seeded postgres, Docker network container seeing varying results”
I was able to solve this issue. It has something to do with Postgres being left in an unstable state after seeding. It doesn’t happen all the time, so not sure when it does or does not.
so the solution is to use a NEW postgres image everytime, and seed the data with a volume container.
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
where seeding-image is your custom docker image that seeds a postgres database.
Recreate and reseed the Postgres container and try again. Most likely that will fix the connection issue you see in the code.