- Newest
- Most votes
- Most comments
Yes, it is possible to use a Docker volume with the scope set to TASK on an EC2 task in Amazon ECS. Your approach is generally correct, but there are a few adjustments and clarifications to consider:
-
Docker volumes with scope set to TASK are indeed suitable for your use case. They are automatically provisioned when the task starts and destroyed when the task stops, ensuring that the data is fresh and empty after each task restart.
-
Your task definition configuration for the volume is correct. Using Scope.TASK will create a new volume for each task instance, which is exactly what you need.
-
The policy you've added to the task execution role is not necessary for using Docker volumes. These permissions are typically used for EBS volumes, not Docker volumes. You can safely remove this policy addition.
-
In your container definition, you're using a "volumes" property, which is not the correct way to mount a Docker volume. Instead, you should use "mountPoints". Here's how you should define it:
mountPoints: [{ sourceVolume: "shareddata", containerPath: "/tmp", readOnly: false }]
-
Make sure you're defining this mountPoint for all three containers that need to share the volume.
-
The "driver": "local" in your volume configuration is correct for EC2 tasks. This is the only supported driver for Windows containers, but it works for Linux containers as well.
If your containers are still failing to start after making these adjustments, the issue might be elsewhere in your configuration. Check the container logs or ECS task status for more specific error messages.
Remember that while all three containers can access this shared volume, the data will only persist for the duration of the task. Once the task stops, the volume and its data will be destroyed, providing you with a fresh, empty volume when the task restarts.
Sources
Specify a Docker volume in an Amazon ECS task definition - Amazon Elastic Container Service
Docker volume examples - Amazon Elastic Container Service
Amazon ECS task definition parameters - Amazon Elastic Container Service
DockerVolumeConfiguration - Amazon Elastic Container Service
Relevant content
asked 2 years ago
asked 2 years ago
