Unlock 100% Persistent Storage for Docker Containers in 5 Steps

Comments · 69 Views

In a perfect scenario, Docker containers should be short-lived and independent of external storage. This is achievable in microservice architecture when services connect to external databases, queues, and other services.

In an ideal scenario, Docker containers should be ephemeral and independent of external storage. This is achievable in microservice architecture when services connect to external databases, queues, and other services. However, certain services like Jenkins, Prometheus, or Postgres require persistent storage, making it essential to set up a reliable storage solution.

Fortunately, attaching EBS volumes to ECS Tasks using Docker volume drivers is now a straightforward process. This article will guide you through the step-by-step process of setting up persistent storage for your Docker containers, ensuring that your ECS Task automatically detaches and reattaches when it restarts. For more information on Docker container storage, visit https://computerstechnicians.com.

Understanding Persistent Storage in ECS

By default, ECS Tasks have a temporary storage area on the host instance, known as the ECS Container Instance, which is essentially an EC2 instance. While this is suitable for temporary data, it's not ideal for persistent storage. To overcome this limitation, we need to connect to external storage solutions like AWS EBS or AWS EFS.

Docker volume plugins, such as REX-Ray, enable us to achieve persistent storage. The REX-Ray plugin can configure AWS services, including creating volumes and attaching them to EC2 instances.

As shown in the diagram below, when an ECS Task runs on an EC2 Instance, the volume (e.g., EBS) needs to be attached to that instance:

virtual private cloud

REX-Ray simplifies the process by:

  • creating the volume if it doesn’t already exist, including configuring volume type and size
  • ensuring our Docker container/ECS Task is mounted with the volume
  • detaching and re-attaching the volume when the ECS Task moves from one EC2 instance to another

ECS Launch Types

ECS offers two launch types: EC2 and Fargate. With EC2, you are responsible for provisioning the underlying EC2 instances on which your ECS Tasks will be deployed. With Fargate, you only need to specify the CPU and memory requirements, and AWS provisions everything needed to run your ECS Task.

It's essential to note that persistent storage is only compatible with the EC2 launch type, not with Fargate. Therefore, in this article, we will focus solely on the EC2 launch type.

Comments