ContainerDefinitionOptions Struct
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,
minHealthyPercent: 100,
cloudMapOptions: {
// Create SRV records - useful for bridge networking
dnsRecordType: cloudmap.DnsRecordType.SRV,
// Targets port TCP port 7600 `specificContainer`
container: specificContainer,
containerPort: 7600,
},
});
Properties
commandstring[]commandtyping.List[str]commandList<String>Commandstring[]Command*[]*string= CMD value built into container i…#If you provide a shell command as a single string, you have to quote command-line arguments.
default
Default: CMD value built into container image.
containerNamestringcontainer_namestrcontainerNameStringContainerNamestringContainerName*string= id of node associated with Conta…#default
Default: id of node associated with ContainerDefinition.
credentialSpecsCredentialSpec[]credential_specstyping.List[CredentialSpec]credentialSpecsList<CredentialSpec>CredentialSpecsCredentialSpec[]CredentialSpecs*[]CredentialSpec= No credential specs.#We recommend that you use this parameter instead of the dockerSecurityOptions.
Currently, only one credential spec is allowed per container definition.
disableNetworkingbooleandisable_networkingbooldisableNetworkingBooleanDisableNetworkingboolDisableNetworking*bool= false#When this parameter is true, networking is disabled within the container.
dnsSearchDomainsstring[]dns_search_domainstyping.List[str]dnsSearchDomainsList<String>DnsSearchDomainsstring[]DnsSearchDomains*[]*string= No search domains.#dnsServersstring[]dns_serverstyping.List[str]dnsServersList<String>DnsServersstring[]DnsServers*[]*string= Default DNS servers.#dockerLabels{ [key: string]: string }docker_labelstyping.Mapping[str, str]dockerLabelsMap<String, String>DockerLabelsIDictionary<string, string>DockerLabels*map[string]*string= No labels.#dockerSecurityOptionsstring[]docker_security_optionstyping.List[str]dockerSecurityOptionsList<String>DockerSecurityOptionsstring[]DockerSecurityOptions*[]*string= No security labels.#enableRestartPolicybooleanenable_restart_policyboolenableRestartPolicyBooleanEnableRestartPolicyboolEnableRestartPolicy*bool= false unless `restartIgnoredExit…#When you set up a restart policy, Amazon ECS can restart the container without needing to replace the task.
default
Default: false unless restartIgnoredExitCodes or restartAttemptPeriod is set.
entryPointstring[]entry_pointtyping.List[str]entryPointList<String>EntryPointstring[]EntryPoint*[]*string= Entry point configured in contai…#default
Default: Entry point configured in container.
environment{ [key: string]: string }environmenttyping.Mapping[str, str]environmentMap<String, String>EnvironmentIDictionary<string, string>Environment*map[string]*string= No environment variables.#environmentFilesEnvironmentFile[]environment_filestyping.List[EnvironmentFile]environmentFilesList<EnvironmentFile>EnvironmentFilesEnvironmentFile[]EnvironmentFiles*[]EnvironmentFile= No environment files.#notes
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{ [key: string]: string }extra_hoststyping.Mapping[str, str]extraHostsMap<String, String>ExtraHostsIDictionary<string, string>ExtraHosts*map[string]*string= No extra hosts.#healthCheckHealthCheckhealth_checkHealthCheckhealthCheckHealthCheckHealthCheckHealthCheckHealthCheckHealthCheck= Health check configuration from …#default
Default: Health check configuration from container.
imageContainerImageimageContainerImageimageContainerImageImageContainerImageImageContainerImagerequired#notes
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
inferenceAcceleratorResourcesstring[]inference_accelerator_resourcestyping.List[str]inferenceAcceleratorResourcesList<String>InferenceAcceleratorResourcesstring[]InferenceAcceleratorResources*[]*string= No inference accelerators assign…#default
Default: No inference accelerators assigned.
linuxParametersLinuxParameterslinux_parametersLinuxParameterslinuxParametersLinuxParametersLinuxParametersLinuxParametersLinuxParametersLinuxParameters= No Linux parameters.#For more information see KernelCapabilities.
loggingLogDriverloggingLogDriverloggingLogDriverLoggingLogDriverLoggingLogDriver= Containers use the same logging …#default
Default: Containers use the same logging driver that the Docker daemon uses.
memoryLimitMiBnumbermemory_limit_mi_bint | floatmemoryLimitMiBNumberMemoryLimitMiBdoubleMemoryLimitMiB*float64= No memory limit.#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.
memoryReservationMiBnumbermemory_reservation_mi_bint | floatmemoryReservationMiBNumberMemoryReservationMiBdoubleMemoryReservationMiB*float64= No memory reserved.#notes
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.
portMappingsPortMapping[]port_mappingstyping.List[PortMapping]portMappingsList<PortMapping>PortMappingsPortMapping[]PortMappings*[]PortMapping= No ports are mapped.#When this parameter is true, the container is given elevated privileges on the host container instance (similar to the root user).
pseudoTerminalbooleanpseudo_terminalboolpseudoTerminalBooleanPseudoTerminalboolPseudoTerminal*bool= false#This parameter maps to Tty in the "Create a container section" of the Docker Remote API and the --tty option to docker run.
readonlyRootFilesystembooleanreadonly_root_filesystemboolreadonlyRootFilesystemBooleanReadonlyRootFilesystemboolReadonlyRootFilesystem*bool= false#restartAttemptPeriodDurationrestart_attempt_periodDurationrestartAttemptPeriodDurationRestartAttemptPeriodDurationRestartAttemptPeriodDuration= Duration.seconds(300) if `enable…#notes · default
A container can be restarted only once every restartAttemptPeriod seconds. If a container isn't able to run for this time period and exits early, it will not be restarted.
This property can't be used if enableRestartPolicy is set to false.
You can set a minimum restartAttemptPeriod of 60 seconds and a maximum restartAttemptPeriod of 1800 seconds.
Default: Duration.seconds(300) if enableRestartPolicy is true, otherwise no period.
restartIgnoredExitCodesnumber[]restart_ignored_exit_codestyping.List[int | float]restartIgnoredExitCodesList<Number>RestartIgnoredExitCodesdouble[]RestartIgnoredExitCodes*[]*float64= No exit codes are ignored.#This property can't be used if enableRestartPolicy is set to false.
You can specify a maximum of 50 container exit codes.
secrets{ [key: string]: Secret }secretstyping.Mapping[str, Secret]secretsMap<String, Secret>SecretsIDictionary<string, Secret>Secrets*map[string]Secret= No secret environment variables.#startTimeoutDurationstart_timeoutDurationstartTimeoutDurationStartTimeoutDurationStartTimeoutDuration= none#stopTimeoutDurationstop_timeoutDurationstopTimeoutDurationStopTimeoutDurationStopTimeoutDuration= none#systemControlsSystemControl[]system_controlstyping.List[SystemControl]systemControlsList<SystemControl>SystemControlsSystemControl[]SystemControls*[]SystemControl= No system controls are set.#This parameter maps to User in the Create a container section of the Docker Remote API and the --user option to docker run.
versionConsistencyVersionConsistencyversion_consistencyVersionConsistencyversionConsistencyVersionConsistencyVersionConsistencyVersionConsistencyVersionConsistencyVersionConsistency= VersionConsistency.DISABLED if `…#If you set the value for a container as disabled, Amazon ECS will not resolve the provided container image tag to a digest and will use the original image URI specified in the container definition for deployment.
default
Default: VersionConsistency.DISABLED if image is a CDK asset, VersionConsistency.ENABLED otherwise
workingDirectorystringworking_directorystrworkingDirectoryStringWorkingDirectorystringWorkingDirectory*string= /#