Amazon Elastic Container Service (ECS) runs Docker containers on AWS. docker-run-export generates either a standalone ECS task definition (JSON) or a CloudFormation template containing an AWS::ECS::TaskDefinition resource. This lets you take a docker run command that works locally and produce the configuration AWS needs to run the same container in the cloud.
docker-run-export run --dre-project myapp --dre-format ecs -e FOO=bar -p 8080:80 --cpus 1 --memory 536870912 alpine:latest echo hellooutput
{
"family": "myapp",
"containerDefinitions": [
{
"name": "app",
"image": "alpine:latest",
"memory": 512,
"portMappings": [
{
"containerPort": 80,
"hostPort": 8080,
"protocol": "tcp"
}
],
"essential": true,
"command": [
"echo",
"hello"
],
"environment": [
{
"name": "FOO",
"value": "bar"
}
]
}
],
"cpu": "1024",
"memory": "512"
}docker-run-export run --dre-project myapp --dre-format ecs-cfn -p 8080:80 alpine:latestoutput
---
AWSTemplateFormatVersion: "2010-09-09"
Resources:
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: myapp
ContainerDefinitions:
- Name: app
Image: alpine:latest
Essential: true
PortMappings:
- ContainerPort: 80
HostPort: 8080
Protocol: tcpThese flags have no docker run equivalent and are prefixed with dre-ecs-. They are also listed in the Command Reference.
--dre-ecs-task-role-arn: IAM role ARN for the task (maps totaskRoleArn)--dre-ecs-execution-role-arn: IAM role ARN for the ECS agent (maps toexecutionRoleArn)--dre-ecs-launch-type: Launch type compatibility, e.g.,FARGATEorEC2(maps torequiresCompatibilities)
--memoryand--memory-reservation: bytes to MiB (e.g.,536870912bytes =512MiB)--cpus: float to ECS CPU units (e.g.,1.0=1024units)--cpu-shares: maps directly to container-levelcpu--health-interval,--health-timeout,--health-start-period: Go duration strings to seconds (e.g.,30s=30)--shm-size: bytes to MiB
Not supported by the ECS task definition specification:
--attach--annotation--blkio-weight--blkio-weight-device--cgroup-parent--cgroupns--cidfile--cpu-period--cpu-quota--cpu-rt-period--cpu-rt-runtime--cpuset-cpus--cpuset-mems--detach--detach-keys--device-cgroup-rule--device-read-bps--device-read-iops--device-write-bps--device-write-iops--disable-content-trust--dns-option--domainname--env-file(ECS uses S3-based environment files instead)--expose--group-add--ip--ip6--isolation--kernel-memory--label-file--link-local-ip--mac-address--network-alias--no-healthcheck--oom-kill-disable--oom-score-adj--pids-limit--publish-all--pull--restart(use ECS service restart policy instead)--rm--runtime--sig-proxy--stop-signal--storage-opt--userns--uts--volume-driver
- The
--networkflag mapshost,none, andbridgedirectly. Other network names are mapped toawsvpcwith a warning. - For Fargate launch type,
networkModemust beawsvpcand CPU/memory must use valid Fargate combinations. - The
--platformflag is converted to ECSruntimePlatform(e.g.,linux/amd64becomescpuArchitecture: X86_64, operatingSystemFamily: LINUX). - A single container named
app(or--namevalue) is always marked asessential: true.