免責聲明

Disclaimer (免責聲明)
繼續閱覽代表您接受以上的免責聲明.
To continue reading means you accept the above disclaimer.

2015年3月9日 星期一

docker cgroup


//=== https://blog.docker.com/2013/10/gathering-lxc-docker-containers-metrics/

*** Control groups are exposed via a pseudo-filesystem 'cgroup'


cgroup location:

/sys/fs/cgroup
or
/cgroup

or find it by
$ grep cgroup /proc/mounts


"""...
different control groups can be in different hierarchies
mean that you can use completely different groups (and policies)
for e.g. CPU allocation and memory allocation.
..."""

$ cat /proc/cgroups





*** to find the memory configs via cgroup for a given container
--> /sys/fs/cgroup/memory/lxc//.

-->
$ cd /sys/fs/cgroup/memory/docker/f177fc8c6f0c208f50...
$ cat memory.stat
...
hierarchical_memory_limit 92233720368
...
$ cat memory.limit_in_bytes
$ cat memory.swappiness



???
"""...
the memory and memsw limits are not really metrics,
but a reminder of the limits applied to this cgroup.
The first one indicates the maximum amount of physical memory that can be used by the processes of this control group;
the second one indicates the maximum amount of RAM+swap.
..."""



//=== short_id to long_id
a container shows short_id as ae836c95b4c3 by
$ docker ps -a

its long_id might be something like ae836c95b4c3c9e9179e0e91015...
-->
$ docker inspect
or
$ docker ps -notrunc




//===
docker run -m
docker run --memory

$ docker run -it --rm --memory 2000M python:2.7



//=== http://stackoverflow.com/questions/20096632/limit-memory-on-a-docker-container-doesnt-work
"""...
$ docker run -m=524288 -d -t busybox sleep 3600

...
$ cat /sys/fs/cgroup/memory/lxc/f03a017b174ff1022e0f46bc1b307658c2d96ffef1dd97e7c1929a4ca61ab80f//memory.limit_in_bytes

... Docker's -m flag does not count swap and ram separately. If you use -m 512M then some of that 512 will be swap, not RAM.

# Same as docker -m 512m
sudo docker run --lxc-conf="lxc.cgroup.memory.limit_in_bytes=512M" -it ubuntu /bin/bash

# Set total to equal max RAM (e.g. don't use swap)
sudo docker run --lxc-conf="lxc.cgroup.memory.max_usage_in_bytes=512M" --lxc-conf="lxc.cgroup.memory.limit_in_bytes=512M" -it ubuntu /bin/bash

..."""

沒有留言:

張貼留言