Dump & Restore PostgreSQL database in a Docker

I was updating my blog and needed to use the same database which I currently have in production. Since my blog is fully dockerized, managing the state of the application between production & development environment is a lot easier. For this purpose, I have researched and learned two handy commands, one to export the database and the other one to import the database. Export (dump) with pg_dump{.single}: 1 docker exec -i container_name /bin/bash -c “PGPASSWORD=actual_password pg_dump —username actual_username database_name” > /path/of/export/export.sql Import (restore) with psql{.single}: 1 docker exec -i container_name /bin/bash -c “PGPASSWORD=actual_password psql —username actual_username database_name” > /path/of/export/export.sql I have noticed successful import even with errors (default PostgreSQL behaviour), because I already had some migrations (in my Django app). Therefore I would recommend first resetting the whole DB and then importing the database. If you want to overwrite this default behaviour and stop upon error, add -set ON_ERROR_STOP=on{.single} to your command. ...

September 13, 2023 · 1 min · 152 words

Django & Docker

I have been reading about Docker for quite some time now. This term would pop up very often whenever I was checking something regarding Django. It wasn’t until recently that I actually made time to read up about it and understand what Docker is. Needless to say, I was missing out. I have now started using Docker with every project, and it makes the development process a lot more manageable. Obviously, I probably understand about 10% of all the features, but I am learning and already these 10% are of tremendous help. ...

December 28, 2022 · 2 min · 292 words