To verify that resource limits were applied correctly to a running Docker container, you can use the docker inspect command. This command provides detailed information about the container's configuration, including memory and CPU limits.
Steps to Verify Resource Limits:
-
Identify the Container Name or ID:
First, ensure you know the name or ID of the container you want to inspect. -
Use the
docker inspectCommand:
Run the following commands to check the memory and CPU limits:-
Check Memory Limit:
docker inspect -f '{{.HostConfig.Memory}}' container_name_or_idThis command will return the memory limit in bytes. For example, if you set a limit of 256MB, it should return
268435456. -
Check CPU Limit:
docker inspect -f '{{.HostConfig.NanoCpus}}' container_name_or_idThis command will return the CPU limit in nano-units. For example, if you set a limit of 0.5 CPUs, it should return
500000000.
-
Example:
If your container is named nginx-limited, you would run:
docker inspect -f '{{.HostConfig.Memory}}' nginx-limited
docker inspect -f '{{.HostConfig.NanoCpus}}' nginx-limited
Additional Information:
- If you want to see all the configuration details, you can simply run:
This will provide a comprehensive JSON output, where you can look for thedocker inspect nginx-limitedHostConfigsection to find resource limits.
Conclusion:
By using the docker inspect command, you can easily verify that the resource limits you set for a container are correctly applied, ensuring that the container operates within the specified constraints.
