How can I attach persistent storage to an AWS Lightsail container?

AWS Lightsail supports container services, with deployment - kind of Docker compose structure. Add multiple containers, specify environment variables, and entrypoint, and choose to add a public IP.

Separately, Lightsail offers storage, as a block device. These can be connected to Lightsail instances.

I've been unable to find how to add persistent storage to a container deployment. What are some good ways to persist files?


Solution 1:

While Docker does support persistent volumes, and Lightsail supports running Docker containers, Lightsail does not support persistent volumes. This is reflected in the lack of any mention of the amount of disk space available for containers in their documentation and pricing for containers. Also they provide a knob to increase or decrease the number of nodes (separate instances of your container running at the same time), which is incompatible with typical implementations of Docker volumes, in which it is assumed that the storage of the volume will be a conventional filesystem (it would typically not be NFS or another network filesystem).

However there are other ways to persist files. Rather than attempting to use the filesystem of the container, you can persist them in Amazon S3. Amazon S3 provides an API for persistent file storage, including the ability to serve URLs for those files directly to the public if you have that requirement.

Similarly, if you need a persistent database you can use Amazon DynamoDB, or Amazon RDS if you prefer something MySQL-compatible.

This means that Amazon's design for lightsail containers is primarily oriented toward hosting applications, such as Node.js applications, that are capable of talking to other Amazon infrastructure to meet their data persistence needs. If you require persistence and want to run your Dockerized application on Amazon, you would be better off looking into Amazon EKS which supports persistent volumes through the Kubernetes Container Storage Interface (CSI).