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.
This topic applies to Docker containers only. For Kubernetes containers, use Kubernetes Pod Label Whitelist and Kubernetes Pod Label Blacklist.
Obtain labels
-
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.
-
List all running containers:
docker psf******ais 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 -
Retrieve the container labels:
docker inspect ${Container ID}The
Labelsfield in the output contains the container labels.
Obtain environment variables
-
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.
-
List all running containers:
docker psf******ais 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 -
Retrieve the container environment variables:
docker exec ${Container ID} env