How do I use EBS volume with ECS container How do I use EBS volume with ECS container linux linux

How do I use EBS volume with ECS container


It sounds like what you potentially want to do is make use of the AWS EC2 Launch Configurations. Using Launch Configurations, you can specify EBS volumes be created and attached to your instance at launch. This happens prior to the docker agent and subsequent tasks being started.

As part of your launch configuration, you'll want to also update the User data under Configure details with something along the lines of:

mkdir /data;mkfs -t ext4 /dev/xvdb;mount /dev/xvdb /data;echo '/dev/xvdb /data ext4 defaults,nofail 0 2' >> /etc/fstab;

Then, so long as your container is setup to access /data on the host, everything will just work the first go.

Bonus: If you're using ECS clusters, I presume you're already making use of Launch Configurations to get your instances joined to the cluster. If not, you can add new instances automatically as well, using something like:

#!/bin/bash docker pull amazon/amazon-ecs-agentdocker run --name ecs-agent --detach=true --restart=on-failure:10 --volume=/var/run/docker.sock:/var/run/docker.sock --volume=/var/log/ecs/:/log --volume=/var/lib/ecs/data:/data --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro   --volume=/var/run/docker/execdriver/native:/var/lib/docker/execdriver/native:ro --publish=127.0.0.1:51678:51678 --env=ECS_LOGFILE=/log/ecs-agent.log --env=ECS_AVAILABLE_LOGGING_DRIVERS=[\"json-file\",\"syslog\",\"gelf\"] --env=ECS_LOGLEVEL=info --env=ECS_DATADIR=/data --env=ECS_CLUSTER=your-cluster-here amazon/amazon-ecs-agent:latest

Specifically in that bit, you'll want to edit this part: --env=ECS_CLUSTER=your-cluster-here

Hope this helps.


The current documentation on Using Data Volumes in Tasks seems to address this problem:

Prior to the release of the Amazon ECS-optimized AMI version 2017.03.a, only file systems that were available when the Docker daemon was started are available to Docker containers. You can use the latest Amazon ECS-optimized AMI to avoid this limitation, or you can upgrade the docker package to the latest version and restart Docker.