I'm running an apache webapp on a container in ecs fargate, but I need to be able to persist certain files so that any changes to them are available to all users through all versions of the webapp. Unfortunately, fargate's support for EFS is in-development, so I need a persistent storage solution at least until that's useable (or until a release date for that feature is announced so I can just say I'll deal with this then).
I tried to switch over from fargate to ec2, as EFS is supposedly compatible with ec2, but I couldn't figure out a way to get past the "unable to place a task because no container instance met all of its requirements. Reason: No Container Instances were found in your cluster." error. I tried all solutions in AWS ECS Error when running task: No Container Instances were found in your cluster , as well as everything I could find in a few google searches, but to no avail.
The way the files are accessed is essentially:
does anyone know of a persistent storage solution for ecs fargate? And how would I go about setting it up?
Different horse for different courses, Fargate is designed to zero management of infrastructure which means just specify the Docker image and then leave everything on AWS.
Bind mount host volumes are supported when using either the EC2 or Fargate launch types. Fargate tasks only support nonpersistent storage volumes, so the host and sourcePath fields are not supported.
The work arround is volume mounts.
When provisioned, each Fargate task receives the following storage. Task storage is ephemeral. After a Fargate task stops, the storage is deleted.
10 GB
of Docker layer storageAn additional
4 GB for volume mounts
. This can be mounted and shared among containers using the volumes, mountPoints and volumesFrom parameters in the task definition.
To provide nonpersistent empty storage for containers in a Fargate task
In this example, you may have two database containers that need to access the same scratch file storage location during a task.
In the task definition volumes section, define a volume with the name database_scratch.
"volumes": [
{
"name": "database_scratch",
"host": {}
}
]
In the containerDefinitions section, create the database container definitions so they mount the nonpersistent storage.
"containerDefinitions": [
{
"name": "database1",
"image": "my-repo/database",
"cpu": 100,
"memory": 100,
"essential": true,
"mountPoints": [
{
"sourceVolume": "database_scratch",
"containerPath": "/var/scratch"
}
]
},
{
"name": "database2",
"image": "my-repo/database",
"cpu": 100,
"memory": 100,
"essential": true,
"mountPoints": [
{
"sourceVolume": "database_scratch",
"containerPath": "/var/scratch"
}
]
}
]
If you are looking for a way to bind host volume then you are expecting wrong from fargate as there is no host in case of fargate.
You need the Ec2 type ECS Task.
To provide persistent storage for containers using a bind mount
When using bind mounts, if a sourcePath value is specified the data persists even after all containers that referenced it have stopped. Any files that exist at the sourcePath are presented to the containers at the containerPath value, and any files that are written to the containerPath value are written to the sourcePath value on the container instance.
In the task definition volumes section, define a bind mount with name and sourcePath values.
"volumes": [
{
"name": "webdata",
"host": {
"sourcePath": "/ecs/webdata"
}
}
]
In the containerDefinitions section, define a container with mountPoints values that reference the name of the defined bind mount and the containerPath value to mount the bind mount at on the container.
"containerDefinitions": [
{
"name": "web",
"image": "nginx",
"cpu": 99,
"memory": 100,
"portMappings": [
{
"containerPort": 80,
"hostPort": 80
}
],
"essential": true,
"mountPoints": [
{
"sourceVolume": "webdata",
"containerPath": "/usr/share/nginx/html"
}
]
}
]
again
The host and sourcePath parameters are not supported for Fargate tasks.