Volumes and Storage
Share data between containers or persist it with bind mounts, EFS, and ephemeral storage.
Containers are ephemeral, so ECS offers several storage options in the task definition's volumes array.
Options
- Ephemeral — scratch space that lives with the task (20 GB by default on Fargate, expandable).
- Bind mounts — share a directory between containers in the same task.
- Amazon EFS — durable, shared file system that survives task restarts.
Example
{
"volumes": [
{
"name": "data",
"efsVolumeConfiguration": {
"fileSystemId": "fs-0abc123",
"transitEncryption": "ENABLED"
}
}
],
"containerDefinitions": [
{
"name": "app",
"image": "app:1",
"mountPoints": [
{
"sourceVolume": "data",
"containerPath": "/var/data"
}
]
}
]
}When to use it
- A service mounts an EFS file system so multiple tasks running across different AZs can share the same configuration files and user uploads.
- An init container writes a config file to a shared bind-mount volume so the main application container can read it at startup without rebuilding the image.
- A developer mounts the Docker socket as a bind mount so a container sidecar can interact with the host Docker daemon for local development testing.
More examples
Shared Bind-Mount Between Containers
Mounts a shared ephemeral volume in two containers: the init container writes config files and the app container reads them after init exits.
{
"volumes": [{"name": "shared-config", "host": {}}],
"containerDefinitions": [
{
"name": "init",
"image": "init-gen:latest",
"mountPoints": [{"sourceVolume": "shared-config", "containerPath": "/config"}],
"essential": false
},
{
"name": "app",
"image": "my-app:latest",
"mountPoints": [{"sourceVolume": "shared-config", "containerPath": "/etc/app-config", "readOnly": true}],
"dependsOn": [{"containerName": "init", "condition": "SUCCESS"}]
}
]
}Mount EFS for Shared Persistent Storage
Mounts an EFS access point at /var/uploads with in-transit encryption so all task replicas share the same persistent file storage.
{
"volumes": [{
"name": "efs-data",
"efsVolumeConfiguration": {
"fileSystemId": "fs-0abc12345",
"rootDirectory": "/uploads",
"transitEncryption": "ENABLED"
}
}],
"containerDefinitions": [{
"name": "app",
"image": "my-app:latest",
"mountPoints": [{"sourceVolume": "efs-data", "containerPath": "/var/uploads"}]
}]
}Expand Fargate Ephemeral Storage
Allocates 100 GiB of ephemeral storage to the Fargate task (above the default 20 GiB) for large intermediate data-processing workloads.
{
"family": "data-processor",
"cpu": "1024",
"memory": "2048",
"requiresCompatibilities": ["FARGATE"],
"networkMode": "awsvpc",
"ephemeralStorage": {"sizeInGiB": 100},
"containerDefinitions": [
{"name": "proc", "image": "data-proc:latest", "essential": true}
]
}
Discussion