- Documentation
Torch Log Service
User Guide
Data collection
LogCollector collection
general reference
Obtain container labels and environment variables
general reference
Obtain container labels and environment variables
Obtain container labels and environment variables
When creating custom K8s container collection configurations in the console, you need to set container labels and environment variables to specify the containers to collect. This topic introduces how to obtain container labels and environment variables after logging in to the host where the container is located.
- Container label: container labels found in Docker inspect.
- Environment variable: environment variables configured when the container starts.
Docker runtime scenario
- Log in to the host where the container is located.
- Run the following command to obtain the container ID.
- hbase is the container name. You need to replace it with the actual container name based on your business needs.
- The first string in the returned result is the container ID, such as 7cbb0bca4d09 in the image below.
-
- Run the following command to get the container's environment variables.
- 7cbb0bca4d09 is the container ID. You need to replace it with the actual container ID based on your business needs.
- The returned result displays the container's environment variables.
docker exec 7cbb0bca4d09 env
-
- Run the following command to get the container label.
- 7cbb0bca4d09 is the container ID. You need to replace it with the actual container ID based on your business needs.
- The Labels field in the returned result is the container label.
docker inspect 7cbb0bca4d09
-
Containerd runtime scenario
- Log in to the host where the container is located.
- Run the following command to obtain the container ID.
- ntp is the container name. Replace it with the actual name as needed
- The first string in the returned result is the container ID, such as 95f7dbb305ade shown below.
-
- Run the following command to get the container's environment variables.
- 95f7dbb305ade is the container ID. You can replace it with the actual container ID you obtained
- The returned result displays the container's environment variables.
crictl exec 95f7dbb305ade env
-
- Run the following command to get the container label.
- 95f7dbb305ade is the container ID. You can replace it with the actual container ID you obtained
- The Labels field in the returned result is the container label.
crictl inspect 95f7dbb305ade
-
Last updated: 2025.12.12 14:35:14