All Products
Search
Document Center

Simple Log Service:How do I obtain Docker container labels and environment variables?

Last Updated:Jun 02, 2026

When you use Logtail to collect container logs, you can filter containers by labels and environment variables. Labels are container metadata returned by the docker inspect command. Environment variables are runtime parameters set at container startup.

Important

This topic applies to Docker containers only. For Kubernetes containers, use Kubernetes Pod Label Whitelist and Kubernetes Pod Label Blacklist.

Obtain labels

  1. Log on to the container host. For more information about how to log on to an ECS instance, see Log on to a Linux instance using Workbench.

  2. List all running containers:

    docker ps

    f******a is the container ID.

    Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
    CONTAINER ID  IMAGE                           COMMAND               CREATED        STATUS        PORTS                 NAMES
    f******a      docker.io/library/nginx:latest  nginx -g daemon o...  6 seconds ago  Up 7 seconds  0.0.0.0:8080->80/tcp  my-nginx
  3. Retrieve the container labels:

    docker inspect ${Container ID}

    The Labels field in the output contains the container labels.

Obtain environment variables

  1. Log on to the container host. For more information about how to log on to an ECS instance, see Log on to a Linux instance using Workbench.

  2. List all running containers:

    docker ps

    f******a is the container ID.

    Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
    CONTAINER ID  IMAGE                           COMMAND               CREATED        STATUS        PORTS                 NAMES
    f******a      docker.io/library/nginx:latest  nginx -g daemon o...  6 seconds ago  Up 7 seconds  0.0.0.0:8080->80/tcp  my-nginx
  3. Retrieve the container environment variables:

    docker exec ${Container ID} env