Friday, April 6, 2018

Docker resource control

systemd-cgls
systemd-cgtop

ls -ltr /sys/fs/cgroup/

https://goldmann.pl/blog/2014/09/11/resource-management-in-docker/


mkdir stress
cd stress/

cat <<EOT >> Dockerfile
FROM fedora:latest
RUN yum -y install stress && yum clean all
ENTRYPOINT ["stress"]
EOT

docker build . -t stress
docker run -d stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 30s
systemd-cgtop


To display the scope of a container:

docker ps --no-trunc
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c82c5d0e0a0dac72ce935fd10c49bb0c6f680f009cdce20995b1c731d9698d80 ubuntu "/usr/bin/top -b" 38 hours ago Up 37 hours topdemo

systemctl show docker-c82c5d0e0a0dac72ce935fd10c49bb0c6f680f009cdce20995b1c731d9698d80.scope


TimeoutStopUSec=1min 30s
Result=success
MemoryCurrent=18446744073709551615
TasksCurrent=18446744073709551615
Delegate=no
CPUAccounting=no
CPUShares=18446744073709551615
StartupCPUShares=18446744073709551615
CPUQuotaPerSecUSec=infinity
BlockIOAccounting=no
BlockIOWeight=18446744073709551615
StartupBlockIOWeight=18446744073709551615
MemoryAccounting=no
MemoryLimit=18446744073709551615
DevicePolicy=auto
TasksAccounting=no
TasksMax=18446744073709551615
KillMode=control-group
KillSignal=15
SendSIGKILL=yes
SendSIGHUP=no
Id=docker-c82c5d0e0a0dac72ce935fd10c49bb0c6f680f009cdce20995b1c731d9698d80.scope
Names=docker-c82c5d0e0a0dac72ce935fd10c49bb0c6f680f009cdce20995b1c731d9698d80.scope
Description=docker-c82c5d0e0a0dac72ce935fd10c49bb0c6f680f009cdce20995b1c731d9698d80.scope
LoadState=not-found
ActiveState=inactive
SubState=dead
InactiveExitTimestampMonotonic=0
ActiveEnterTimestampMonotonic=0
ActiveExitTimestampMonotonic=0
InactiveEnterTimestampMonotonic=0
CanStart=yes
CanStop=yes
CanReload=no
CanIsolate=no
StopWhenUnneeded=no
RefuseManualStart=no
RefuseManualStop=no
AllowIsolate=no
DefaultDependencies=yes
OnFailureJobMode=replace
IgnoreOnIsolate=yes
IgnoreOnSnapshot=yes
NeedDaemonReload=no
JobTimeoutUSec=0
JobTimeoutAction=none
ConditionResult=no
AssertResult=no
ConditionTimestampMonotonic=0
AssertTimestampMonotonic=0
LoadError=org.freedesktop.DBus.Error.FileNotFound "No such file or directory"
Transient=no


cat /proc/meminfo

cat /proc/vmstat


#remove all containers with stress image
docker ps -a | awk '{ print $1,$2 }' | grep stress | awk '{print $1 }' | xargs -I {} docker rm {}
#or even better
docker ps -a -q --filter=ancestor=stress | xargs -I {} docker rm {}

dockerd --iptables=false



References

https://www.javacodegeeks.com/minibook/docker-containerization-cookbook

https://fralef.me/docker-and-iptables.html




No comments: