In Amazon ECS (Elastic Container Service), the concept of “essential” and “non-essential” containers refers to the importance of specific containers within a task definition. This distinction is used to determine how the task behaves when individual containers exit or fail.
Essential Containers
- Definition: An essential container is a critical part of the task. If this container stops or exits with an error, the entire task will stop.
- Behavior: If an essential container fails, ECS will consider the task as failed and will potentially stop all other containers in the task. The task might be restarted or terminated based on the task’s
restart policy. - Use Case: Essential containers are typically the main components of an application, like a web server, primary service, or a critical process that the task cannot function without.
Non-Essential Containers
- Definition: A non-essential container is considered supplementary. If this container stops or exits, the task will continue to run as long as all essential containers are running.
- Behavior: The failure of a non-essential container will not cause the entire task to stop. However, the status of the non-essential container will be reported as stopped.
- Use Case: Non-essential containers are often used for auxiliary tasks like logging, monitoring, or sidecar containers that provide additional but non-critical functionality.
Example Scenario
Imagine a task with two containers:
- Container A (Essential): A web server that serves application traffic.
- Container B (Non-Essential): A logging agent that forwards logs to a remote server.
If Container A fails, the entire task will stop. If Container B fails, the task will continue running, but logs might not be forwarded until the logging container is restarted or replaced.
Configuration
In the ECS task definition JSON, you can specify whether a container is essential or non-essential by setting the essential parameter:
jsonCopy code{
"containerDefinitions": [
{
"name": "web-server",
"image": "nginx",
"essential": true
},
{
"name": "log-agent",
"image": "log-agent-image",
"essential": false
}
]
}
In this example, “web-server” is essential, while “log-agent” is non-essential.










