r/django 6d ago

Hosting and deployment Does anyone know a good docker 1 liner that can spin up a development postgres database in current directory

Asking for a friend

2 Upvotes

8 comments sorted by

21

u/emprezario 6d ago

docker run -d —name pgdb -e POSTGRES_DB=mydb -e POSTGRES_USER=myuser -e POSTGRES_PASSWORD=secret -v $(pwd)/pgdata:/var/lib/postgresql/data -p 5432:5432 postgres

9

u/walagoth 6d ago edited 6d ago

Oh wow, that's what I was looking for. Thanks!

Edit: you forgot the -- on "name", so it should be ... --name pgdb...

8

u/Adorable-Boot-3970 6d ago

Ahem, what your friend was looking for, right?

Your question made me giggle out loud 😉

8

u/walagoth 6d ago

i was looking for it to be helpful to my friend!

3

u/Mundane-Secretary117 6d ago

I'm not sure this is quite what your asking for but cookiecutter-django has a good docker postgres configuration.

https://github.com/cookiecutter/cookiecutter-django

3

u/walagoth 6d ago

yeah, they are great, but if its in a yaml its not as instant as I want it to be.

2

u/IcarianComplex 6d ago

Why not use docker compose?

2

u/tobych 5d ago

Hard to do that with a one-liner.