Decoupling Data from the Container

It’s great that we’ve set up our database so we can persist data in our Rails app. However, currently, there’s a major failing in how it works. Let’s see what the problem is, and see how to get around it.

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 is running in a container and persisting 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’ve guessed it: we say bye bye to all our lovely data. Not really what we want.

Now that we’re going to be storing important data in our database, we need to ...

Get Docker for Rails Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.