How to use an EBS volume with an ECS container

I created an EBS volume, connected and installed it in my container instance. In task definition volumes, I set the source path of the source with the directory installed. Container data is not created in the mounted directory; all other directories from the installed EBS work correctly.

The goal is to save data from the container and with this other volume backup.

Is there any way to use this attached volume with my container? or this is the best way to work with volumes and backups.

EDIT : It was tested using a random docker image in which it indicated the volume, and I ran into the same problem. I manage to get it to restart the Docker service, but I'm still looking for a solution without restarting the Docker.

Checking the volume catalog container that is installed by EBS

"HostConfig": { "Binds": [ "/mnt/data:/data" ], ... "Mounts": [ { "Source": "/mnt/data", "Destination": "/data", "Mode": "", "RW": true, "Propagation": "rprivate" } ], 

displayed directory:

 $ ls /mnt/data/ lost+found 

Checking a container with a volume that is not installed by EBS

 "HostConfig": { "Binds": [ "/home/ec2-user/data:/data" ], ... "Mounts": [ { "Source": "/home/ec2-user/data", "Destination": "/data", "Mode": "", "RW": true, "Propagation": "rprivate" } ] 

displayed directory:

 $ ls /home/ec2-user/data databases dbms 
+5
source share
1 answer

Looks like what you want to do is use AWS EC2 Launch Configurations . Using Launch Configurations, you can specify the EBS volumes that will be created and attached to your instance at startup. This happens before the docker agent and subsequent running tasks.

As part of the startup configuration, you will also want to update the User Data in the Configure Parts section using the following lines:

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

Then, while your container is configured to access /data on the host, everything will work only the first time.

Bonus: if you use ECS clusters, I assume that you are already using the startup configuration so that your instances join the cluster. If not, you can add new instances automatically using something like:

 #!/bin/bash docker pull amazon/amazon-ecs-agent docker 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 

In particular, in this bit you want to edit this part: --env=ECS_CLUSTER=your-cluster-here

Hope this helps.

+2
source

All Articles