All Products
Search
Document Center

Simple Log Service:How do I obtain the labels and environment variables of a container?

Last Updated:Aug 29, 2023

Simple Log Service allows you to collect logs from containers. You can specify the containers by label or environment variable. Labels are retrieved by running the docker inspect command and environment variables are specified in the startup configuration of each container.

Obtain container labels

  1. Log on to the host where the container whose labels you want to obtain resides, for example, an Elastic Compute Service (ECS) instance.

  2. Run the following command to obtain the ID of the container.

    The orders variable in the command is the name of a container group. Replace the value of the variable with an actual name.

    docker ps | grep orders

    2ba4ebdaf503 in the response indicates the ID of the container.

    Obtain the ID of a container
  3. Run the following command to obtain the labels of the container.

    The 2ba4ebdaf503 variable in the command is the ID of a container. Replace the value of the variable with an actual ID.

    docker inspect 2ba4ebdaf503

    The Labels field in the response indicates the container labels.

    Obtain container labels

Obtain environment variables

  1. Log on to the host where the container whose labels you want to obtain resides, for example, an Elastic Compute Service (ECS) instance.

  2. Run the following command to obtain the ID of the container.

    The orders variable in the command is the name of a container group. Replace the value of the variable with an actual name.

    docker ps | grep orders

    2ba4ebdaf503 in the response indicates the ID of the container.

    Obtain the ID of a container
  3. Run the following command to obtain the environment variables of the container.

    The 2ba4ebdaf503 variable in the command is the ID of a container. Replace the value of the variable with an actual ID.

    docker exec 2ba4ebdaf503 env
    Environment variables