Skip to content

Persisting data across restarts

When you run your application on Patr, your application is running inside a container. This means that any data that is stored within the container will be lost when the container is restarted. It's important to understand this behavior when designing your application architecture.

Despite this limitation, using containers has many advantages. Containers allow you to isolate your application from the underlying host environment, making it easier to manage and deploy. They provide a consistent environment for your application to run in, regardless of where it's deployed. Containers are also lightweight, allowing you to run multiple instances of your application on a single host.

To work with this limitation, it's important to design your application to be stateless. This means that your application does not rely on any data being stored within the container, and can function correctly even if the container is restarted. Stateless applications are easier to scale horizontally, as you can simply add more instances of the application to handle increased load. They are also easier to manage, as there is no data that needs to be persisted across container restarts.

However, in certain scenarios, it is unavoidable to build your application to be completely stateless (for example, WordPress, RabbitMQ, etc). For these situations, you can attach a volume to your Deployment, and any file that is created in the volume will be persisted across restarts.

Setting up your Deployment with Volumes

While creating a Deployment, you will have the option to choose a Volume to attach to your Deployment. Here, you can choose to have as many Volumes as you need, attached to your Deployment. Each Volume can be mounted at a specific location in your Deployment's container, and can have any size.

Screenshot of create deployment screen 2

When a Volume is set for your Deployment, Patr will assign a fresh volume for each instance of your Deployment, and all data that is stored in the Volume will be completely persisted across restart. Once your Deployment is created, the number of Volumes in the Deployment cannot be changed. The size of the Volume cannot be shrunk either. However, if you need more storage, you can always increase the Volume size, and Patr will automatically take care of expanding your filesystem.

In conclusion, understanding how data is stored and managed within containers is an important part of designing and deploying applications on Patr. By designing your application to be stateless, you can take advantage of the benefits of containerization while avoiding the limitations of data persistence within containers. However, if you ever are in a situation where your use-case requires you to use Volumes, Patr has your back!

Further Reading

Pushing an image to Patr's Container Registry
Deploying a Static Site