Saturday, 18 January 2020

How to best dockerise a Node.js + Postgres project?

I've been working on dockerising a Node.js + Postgres application, I've set it up such that the docker-compose file utilises a .env file that is passed both to Postgres to set the database credentials, and also to the Node.js application to connect using these, the file also networks the two together.It's all working but I am unsure if this is the best practice way to do this, it's quite hard to know what is the right approach as often Node is used with Mongo and so there are few examples of Node + Postgres.https://github.com/creativetechnologylab/checkout/blob/master/docker-compose.ymlhttps://github.com/creativetechnologylab/checkout/blob/master/docker.env.examplehttps://github.com/creativetechnologylab/checkout/blob/master/DockerfileOne thing that I am still stuck on is how to 'fix' the first run setup, i.e. when the database is empty the application just sits there crashing over and over until you use docker exec to run the database migrations and seed using knex.I'm also unsure if the best way to persist the data is to mount the Postgres data folder somewhere.Any feedback would be appreciated, I felt this was a better place to ask that r/docker due to the environment specific-ness of the question.

Submitted January 18, 2020 at 09:42PM by unknowndomain

No comments:

Post a Comment