All Products
Search
Document Center

Elastic Container Instance:Use probes for container health checks

Last Updated:Jun 20, 2026

Liveness and readiness probes are mechanisms that check a container's status. A liveness probe determines if the container is running properly, while a readiness probe determines if it is ready to serve requests. This topic describes how to configure liveness and readiness probes for containers in Elastic Container Instance (ECI). These probes help ECI monitor and manage your containers' state, ensuring high service availability and stability.

Overview

ECI supports liveness probes and readiness probes to check the health and status of containers.

Probe

Description

Use cases

liveness probe

Checks if a container is running properly.

  • If the check succeeds, the container is considered healthy.

  • If the check fails, the system restarts the container based on its configured restart policy.

  • If a liveness probe is not configured, the container is always considered healthy.

  • A liveness probe can detect a deadlock. For example, if an application is running but unable to make progress, the probe restarts the container to help it recover.

  • Long-running applications may enter a broken state from which they cannot recover without a restart. A liveness probe can detect and remedy this situation.

readiness probe

Checks if a container is ready to accept and serve requests.

  • If the check succeeds, the container is considered ready and can receive traffic.

  • If the check fails, the container is not ready, and the system stops sending traffic to it until the probe succeeds again.

  • If a readiness probe is not configured, the container is considered ready immediately after it starts.

Use a readiness probe if an application is temporarily unable to serve traffic, for example, while loading large amounts of data or configuration files during startup. In such cases, you do not want to terminate the application, but you do want to temporarily stop sending it requests.

API configuration

When creating an ECI instance with the CreateContainerGroup operation, you can configure probes using the LivenessProbe and ReadinessProbe parameters. For more information, see CreateContainerGroup.

LivenessProbe parameters

Important

When you configure LivenessProbe parameters, you can specify only one check method: HttpGet, Exec, or TcpSocket.

Parameter

Type

Example

Description

Container.N.LivenessProbe.HttpGet.Path

string

/healthyz

The path for the HTTP GET health check request.

Container.N.LivenessProbe.HttpGet.Port

integer

8888

The port for the HTTP GET health check request.

Container.N.LivenessProbe.HttpGet.Scheme

string

HTTP

The protocol of the HTTP GET request. Valid values:

  • HTTP

  • HTTPS

Container.N.LivenessProbe.Exec.Command.N

array

cat /tmp/healthy

The command to run inside the container for the health check.

Container.N.LivenessProbe.TcpSocket.Port

integer

8000

The port to check for the TCP socket health check.

Container.N.LivenessProbe.InitialDelaySeconds

integer

5

The delay in seconds after the container starts before the first probe runs.

Container.N.LivenessProbe.PeriodSeconds

integer

1

The interval at which the probe runs. Default value: 10. Minimum value: 1. Unit: seconds.

Container.N.LivenessProbe.SuccessThreshold

integer

1

The number of consecutive successes required for the probe to be considered successful after a failure. This value must be 1 for liveness probes. Default: 1.

Container.N.LivenessProbe.FailureThreshold

integer

3

The number of consecutive failures required for the probe to be considered failed. Default value: 3.

Container.N.LivenessProbe.TimeoutSeconds

integer

1

The number of seconds after which the probe times out. Default value: 1. Minimum value: 1. Unit: seconds.

ReadinessProbe parameters

Important

When you configure ReadinessProbe parameters, you can specify only one check method: HttpGet, Exec, or TcpSocket.

Parameter

Type

Example

Description

Container.N.ReadinessProbe.HttpGet.Path

string

/healthyz

The path for the HTTP GET health check request.

Container.N.ReadinessProbe.HttpGet.Port

integer

8888

The port for the HTTP GET health check request.

Container.N.ReadinessProbe.HttpGet.Scheme

string

HTTP

The protocol of the HTTP GET request. Valid values:

  • HTTP

  • HTTPS

Container.N.ReadinessProbe.Exec.Command.N

array

cat /tmp/healthy

The command to run inside the container for the health check.

Container.N.ReadinessProbe.TcpSocket.Port

integer

8000

The port to check for the TCP socket health check.

Container.N.ReadinessProbe.InitialDelaySeconds

integer

5

The delay in seconds after the container starts before the first probe runs.

Container.N.ReadinessProbe.PeriodSeconds

integer

1

The interval at which the probe runs. Default value: 10. Minimum value: 1. Unit: seconds.

Container.N.ReadinessProbe.SuccessThreshold

integer

1

The minimum number of consecutive successes required for the probe to be considered successful after a failure. Default: 1. Minimum: 1.

Container.N.ReadinessProbe.FailureThreshold

integer

3

The number of consecutive failures required for the probe to be considered failed. Default value: 3.

Container.N.ReadinessProbe.TimeoutSeconds

integer

1

The number of seconds after which the probe times out. Default value: 1. Minimum value: 1. Unit: seconds.

Console configuration

When you create an ECI instance in the Elastic Container Instance console, you can select a container in the Container Configurations section, expand the container's advanced settings, enable health checks, and then configure the probes.

Note

When you configure probes in the console, only the command line and HTTP request methods are supported. The TCP socket method is not supported.

Parameter

Description

Timeout Period

  • Waiting Period: The time in seconds to wait after the container starts before the first probe runs. This corresponds to the initialDelaySeconds API parameter.

  • Timeout Period: The time in seconds after which the probe times out. If a probe times out, it is considered a failure. This corresponds to the timeoutSeconds API parameter.

Method

Select a check method.

  • Script: The probe runs a command inside the container. If the command exits with a status code of 0, the check is successful.

  • HTTP Request: The probe sends an HTTP request to the container. If the response status code is greater than or equal to 200 and less than 400 (2xx or 3xx), the check is successful.

Script

If you select Script as the check method, you must specify the command to run in the container.

HTTP Request

If you select HTTP Request as the check method, you must specify the path, port, and protocol for the HTTP GET request.

Example

This example shows how to create an ECI instance with a liveness probe and a readiness probe, and then simulate a service failure to see the probes in action.

  1. Call the CreateContainerGroup operation to create an ECI instance.

    The following example uses the TCP socket method for health checks:

    ContainerGroupName=test-probe
    # Use the nginx image and automatically create and associate an EIP.
    Container.1.Name=container-1
    Container.1.Image=nginx
    AutoCreateEip=true
    # Liveness probe: checks port 80 every 3s, starting 5s after launch. Success threshold: 1, failure threshold: 3, timeout: 10s.
    Container.1.LivenessProbe.TcpSocket.Port=80
    Container.1.LivenessProbe.InitialDelaySeconds=5
    Container.1.LivenessProbe.PeriodSeconds=3
    Container.1.LivenessProbe.SuccessThreshold=1
    Container.1.LivenessProbe.FailureThreshold=3
    Container.1.LivenessProbe.TimeoutSeconds=10
    # Readiness probe: checks port 80 every 3s, starting 5s after launch. Success threshold: 1, failure threshold: 3, timeout: 10s.
    Container.1.ReadinessProbe.TcpSocket.Port=80
    Container.1.ReadinessProbe.InitialDelaySeconds=5
    Container.1.ReadinessProbe.PeriodSeconds=3
    Container.1.ReadinessProbe.SuccessThreshold=1
    Container.1.ReadinessProbe.FailureThreshold=3
    Container.1.ReadinessProbe.TimeoutSeconds=10
  2. View the ECI instance events in the Elastic Container Instance console.

    After the ECI instance is created, click the instance ID to open its details page. On the Events tab, you can see that the container started normally.

    The event list shows four Normal events in order: Pulling image "nginx", Successfully pulled image "nginx", Created container container-1, and Started container container-1.

  3. Connect to the container. For more information, see Connect to an ECI instance with Workbench.

  4. Change the Nginx listening port to simulate a service failure.

    1. Modify the Nginx listening port.

      Note

      The Nginx image used in this example does not have vim installed. Before you run the vi command, run apt-get update and apt-get install vim to install vim.

      vi /etc/nginx/conf.d/default.conf

      Change the listening port from 80 to 8080, as shown in the following example:

      server {
          listen       8080;
          listen  [::]:8080;
          server_name  localhost;
          #access_log  /var/log/nginx/host.access.log  main;
          location / {
              root   /usr/share/nginx/html;
              index  index.html index.htm;
          }
          #error_page  404              /404.html;
          # redirect server error pages to the static page /50x.html
          #
          error_page   500 502 503 504  /50x.html;
          location = /50x.html {
              root   /usr/share/nginx/html;
          }
      }
    2. Reload the Nginx configuration.

      nginx -s reload
  5. Check the effect of the probes.

    A few seconds after you reload Nginx, the container automatically restarts. You can view the instance events to see the container restart after the liveness and readiness probes fail.

    The event list shows that the probes failed with the message dial tcp 172.x.x.x:80: connect: connection refused, which indicates that the connection to the container port was refused. As a result, ECI automatically restarted the container-1 container.