15

UPDATE:

found a lot of questions and discussions on stackoverflow about this topic. And although they are marked as accepted answered and started by thousands of users, they do not seem to be the right answer here.


I ran a docker (version 1.13.1, build 092cba3) container with resource constraints as follows:

docker run --privileged -v /sys/fs/cgroup:/sys/fs/cgroup -m 4096M --cpuset-cpus='0' --cpus=1 --cpu-shares=256 -p $IMAGE_NAME

The host system (RHEL 7) has 4 cores and 8G memory. Basically I want to restrict the available memory and CPU for the container. After successfully launched the container, I opened the bash and tried to find the limit information from within the container. But I wasn't able to get the correct information.

I tried this:

sudo cat /proc/meminfo

The result is:

Host system MemTotal: 8008812 kB MemFree: 7416404 kB MemAvailable: 7537332 kB
Docker Container MemTotal: 8008812 kB MemFree: 7318052 kB MemAvailable: 7498764 kB

Similarly, I wanted to get CPU limit:

grep -c ^processor /proc/cpuinfo

The result is:

Host system 4
Docker Image 4

It seems that the CPU and memory limit enforced by container is not visible by the container. I also tried to query cgroup information.

mkdir -p /tmp/memory
mount -n -t cgroup -o memory cgroup /tmp/memory

Then I look into the cgroup files:

[root@engrlab memory]# cat /tmp/memory/memory.limit_in_bytes
9223372036854771712

This number is greater than the actual memory of the host system.

Is there a way to verify that the resource constraints has been correctly set in container? How do I find the resource constraint info from within a container? Appreciate any suggestion.

0

2 Answers 2

6

I try this command this my docker host which is working

docker run -it -d -m 100M --cpuset-cpus='0' --cpus=1 --cpu-shares=256 --name testing ubuntu /bin/bash

docker stats testing

4

UPDATE

This is the answer that works: https://stackoverflow.com/a/41827812/3209177


I have just found this answer:

Limit memory on a docker container doesn't work

I am going to try that and come back with my observation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.