Goal
- Establish a centralized postgres db that all other compose files / containers can access
- Allow other containers to automatically create credentials/databases that are scoped specifically for them
- Make sure that the databases aren't overwritten each time
docker-compose up -d
is ran - Avoid having to duplicate entrypoint files and keep the postgres_entrypoint.sh in a centralized location
File Structure
ποΈ docker
|___ ποΈ DummyStack
| |___ π docker-compose.yml
| |___ π .env
|___ ποΈ Postgres
| |___ π docker-compose.yml
| |___ π postgres_entrypoint.sh
| |___ π .env
Logic Flow
- Postgres is running in the background
- New docker-compose is created elsewhere (dummyStack)
- When
docker-compose up -d
is ran on the dummyStack, dummyStack calls up Postgres and says "Hey! Pleasure to meet you. Can you please create a database called dummyStack and allow me (I go by dummystack and I want a password of pass123)" - Postgres checks to see if dummyStack has already been there before A. Postgres says "You big dummy, you were my Made of Honor at me and Redis's wedding and we've been friends since middle school. You gotta stop poppin' Ambien." To which DummyStack says, "Oh my bad, I've been hitting the Ambien hard lately because the world is coming to an end, I'll never be able to afford a house of my own, the rich are getting richer, and democracy is a lie perpetuated by the elite in an attempt to keep us complacent. I'm coming over with the house key you gave me and moving my shit into your garage" B. Postgres says "Great to meet you as well, here's a house key, come on over and throw your shit in my garage"
- DummyStack proceeds to throw his shit in Postgres's garage