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.
Fargate Task Storage
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 storage
An 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"
}
]
}
]
bind-mounts
again
The host and sourcePath parameters are not supported for Fargate tasks.