Created
May 25, 2014 13:21
-
-
Save jumanjiman/b0735411e54281ad0855 to your computer and use it in GitHub Desktop.
memory limits in docker containers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Demonstrate memory resource limits in docker | |
# See also http://stackoverflow.com/a/20111960 | |
function demo() { | |
mem=$1 | |
echo "Run a container and limit to $mem" | |
cid=$(docker run -d -m $mem busybox /bin/sh -c "tail -f /var/log/*") | |
file=$(find /sys -regex ".*$cid.*memory.limit_in_bytes" 2> /dev/null) | |
bytes=$(cat $file) | |
MiB=$(( $bytes / 1024**2 )) | |
printf '%-25s %s (%s Mebibytes)\n' $(basename $file) $bytes $MiB | |
echo "Stop and remove $cid" | |
docker stop $cid &> /dev/null | |
docker rm $cid &> /dev/null | |
echo | |
} | |
for mem in 1M 512M 1G; do | |
demo $mem | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Run a container and limit to 1M | |
memory.limit_in_bytes 1048576 (1 Mebibytes) | |
Stop and remove 5976e05f443062da3fcd3fda8bedc4f9dcf83c675b6abb5473bf4e20ba1c46fd | |
Run a container and limit to 512M | |
memory.limit_in_bytes 536870912 (512 Mebibytes) | |
Stop and remove 733d8fd1d27518189e5730677f6bc9c901f8ae5e7940bb2bd402f6be275b849d | |
Run a container and limit to 1G | |
memory.limit_in_bytes 1073741824 (1024 Mebibytes) | |
Stop and remove 036f2f01a5c9db4f30fcb6354c7c5a4125787c72b5cf49088b4ce2cf6405bb85 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment