Decoupling Data From a Container
Learn how to decouple our container so the data stored in our database isn't lost.
It is great that we have set up our database so we can persist data in our Rails app. However, currently, there is a major failing in how it works. Let’s see what the problem is and see how to get around it.
The Postgres container problem
Part of the philosophy of using Docker is that we should treat containers as ephemeral, throwaway things that we spin up, use, and then delete.
However, our Postgres database runs in a container and persists our data by writing and modifying files on disk inside the container. What happens to our data if we delete our database container? Yep, you guessed it: we say bye-bye to all our lovely data. Not really what we want.
Now that we are going to be storing important data in our database, we need to think a bit more carefully about this. Just like in our code where we try to decouple things that change frequently from things that do not, here we want to decouple the containers that ...