interface ContainerDefinitionOptions
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.ECS.ContainerDefinitionOptions |
Java | software.amazon.awscdk.services.ecs.ContainerDefinitionOptions |
Python | aws_cdk.aws_ecs.ContainerDefinitionOptions |
TypeScript (source) | @aws-cdk/aws-ecs » ContainerDefinitionOptions |
Example
declare const taskDefinition: ecs.TaskDefinition;
declare const cluster: ecs.Cluster;
// Add a container to the task definition
const specificContainer = taskDefinition.addContainer('Container', {
image: ecs.ContainerImage.fromRegistry('/aws/aws-example-app'),
memoryLimitMiB: 2048,
});
// Add a port mapping
specificContainer.addPortMappings({
containerPort: 7600,
protocol: ecs.Protocol.TCP,
});
new ecs.Ec2Service(this, 'Service', {
cluster,
taskDefinition,
cloudMapOptions: {
// Create SRV records - useful for bridge networking
dnsRecordType: cloudmap.DnsRecordType.SRV,
// Targets port TCP port 7600 `specificContainer`
container: specificContainer,
containerPort: 7600,
},
});
Properties
Name | Type | Description |
---|---|---|
image | Container | The image used to start a container. |
command? | string[] | The command that is passed to the container. |
container | string | The name of the container. |
cpu? | number | The minimum number of CPU units to reserve for the container. |
disable | boolean | Specifies whether networking is disabled within the container. |
dns | string[] | A list of DNS search domains that are presented to the container. |
dns | string[] | A list of DNS servers that are presented to the container. |
docker | { [string]: string } | A key/value map of labels to add to the container. |
docker | string[] | A list of strings to provide custom labels for SELinux and AppArmor multi-level security systems. |
entry | string[] | The ENTRYPOINT value to pass to the container. |
environment? | { [string]: string } | The environment variables to pass to the container. |
environment | Environment [] | The environment files to pass to the container. |
essential? | boolean | Specifies whether the container is marked essential. |
extra | { [string]: string } | A list of hostnames and IP address mappings to append to the /etc/hosts file on the container. |
gpu | number | The number of GPUs assigned to the container. |
health | Health | The health check command and associated configuration parameters for the container. |
hostname? | string | The hostname to use for your container. |
inference | string[] | The inference accelerators referenced by the container. |
linux | Linux | Linux-specific modifications that are applied to the container, such as Linux kernel capabilities. |
logging? | Log | The log configuration specification for the container. |
memory | number | The amount (in MiB) of memory to present to the container. |
memory | number | The soft limit (in MiB) of memory to reserve for the container. |
port | Port [] | The port mappings to add to the container definition. |
privileged? | boolean | Specifies whether the container is marked as privileged. |
readonly | boolean | When this parameter is true, the container is given read-only access to its root file system. |
secrets? | { [string]: Secret } | The secret environment variables to pass to the container. |
start | Duration | Time duration (in seconds) to wait before giving up on resolving dependencies for a container. |
stop | Duration | Time duration (in seconds) to wait before the container is forcefully killed if it doesn't exit normally on its own. |
system | System [] | A list of namespaced kernel parameters to set in the container. |
user? | string | The user name to use inside the container. |
working | string | The working directory in which to run commands inside the container. |
image
Type:
Container
The image used to start a container.
This string is passed directly to the Docker daemon. Images in the Docker Hub registry are available by default. Other repositories are specified with either repository-url/image:tag or repository-url/image@digest. TODO: Update these to specify using classes of IContainerImage
command?
Type:
string[]
(optional, default: CMD value built into container image.)
The command that is passed to the container.
If you provide a shell command as a single string, you have to quote command-line arguments.
containerName?
Type:
string
(optional, default: id of node associated with ContainerDefinition.)
The name of the container.
cpu?
Type:
number
(optional, default: No minimum CPU units reserved.)
The minimum number of CPU units to reserve for the container.
disableNetworking?
Type:
boolean
(optional, default: false)
Specifies whether networking is disabled within the container.
When this parameter is true, networking is disabled within the container.
dnsSearchDomains?
Type:
string[]
(optional, default: No search domains.)
A list of DNS search domains that are presented to the container.
dnsServers?
Type:
string[]
(optional, default: Default DNS servers.)
A list of DNS servers that are presented to the container.
dockerLabels?
Type:
{ [string]: string }
(optional, default: No labels.)
A key/value map of labels to add to the container.
dockerSecurityOptions?
Type:
string[]
(optional, default: No security labels.)
A list of strings to provide custom labels for SELinux and AppArmor multi-level security systems.
entryPoint?
Type:
string[]
(optional, default: Entry point configured in container.)
The ENTRYPOINT value to pass to the container.
See also: https://docs.docker.com/engine/reference/builder/#entrypoint
environment?
Type:
{ [string]: string }
(optional, default: No environment variables.)
The environment variables to pass to the container.
environmentFiles?
Type:
Environment
[]
(optional, default: No environment files.)
The environment files to pass to the container.
essential?
Type:
boolean
(optional, default: true)
Specifies whether the container is marked essential.
If the essential parameter of a container is marked as true, and that container fails or stops for any reason, all other containers that are part of the task are stopped. If the essential parameter of a container is marked as false, then its failure does not affect the rest of the containers in a task. All tasks must have at least one essential container.
If this parameter is omitted, a container is assumed to be essential.
extraHosts?
Type:
{ [string]: string }
(optional, default: No extra hosts.)
A list of hostnames and IP address mappings to append to the /etc/hosts file on the container.
gpuCount?
Type:
number
(optional, default: No GPUs assigned.)
The number of GPUs assigned to the container.
healthCheck?
Type:
Health
(optional, default: Health check configuration from container.)
The health check command and associated configuration parameters for the container.
hostname?
Type:
string
(optional, default: Automatic hostname.)
The hostname to use for your container.
inferenceAcceleratorResources?
Type:
string[]
(optional, default: No inference accelerators assigned.)
The inference accelerators referenced by the container.
linuxParameters?
Type:
Linux
(optional, default: No Linux parameters.)
Linux-specific modifications that are applied to the container, such as Linux kernel capabilities.
For more information see KernelCapabilities.
logging?
Type:
Log
(optional, default: Containers use the same logging driver that the Docker daemon uses.)
The log configuration specification for the container.
memoryLimitMiB?
Type:
number
(optional, default: No memory limit.)
The amount (in MiB) of memory to present to the container.
If your container attempts to exceed the allocated memory, the container is terminated.
At least one of memoryLimitMiB and memoryReservationMiB is required for non-Fargate services.
memoryReservationMiB?
Type:
number
(optional, default: No memory reserved.)
The soft limit (in MiB) of memory to reserve for the container.
When system memory is under heavy contention, Docker attempts to keep the container memory to this soft limit. However, your container can consume more memory when it needs to, up to either the hard limit specified with the memory parameter (if applicable), or all of the available memory on the container instance, whichever comes first.
At least one of memoryLimitMiB and memoryReservationMiB is required for non-Fargate services.
portMappings?
Type:
Port
[]
(optional, default: No ports are mapped.)
The port mappings to add to the container definition.
privileged?
Type:
boolean
(optional, default: false)
Specifies whether the container is marked as privileged.
When this parameter is true, the container is given elevated privileges on the host container instance (similar to the root user).
readonlyRootFilesystem?
Type:
boolean
(optional, default: false)
When this parameter is true, the container is given read-only access to its root file system.
secrets?
Type:
{ [string]:
Secret
}
(optional, default: No secret environment variables.)
The secret environment variables to pass to the container.
startTimeout?
Type:
Duration
(optional, default: none)
Time duration (in seconds) to wait before giving up on resolving dependencies for a container.
stopTimeout?
Type:
Duration
(optional, default: none)
Time duration (in seconds) to wait before the container is forcefully killed if it doesn't exit normally on its own.
systemControls?
Type:
System
[]
(optional, default: No system controls are set.)
A list of namespaced kernel parameters to set in the container.
user?
Type:
string
(optional, default: root)
The user name to use inside the container.
workingDirectory?
Type:
string
(optional, default: /)
The working directory in which to run commands inside the container.