Created
February 26, 2016 00:26
-
-
Save samuelkarp/6c8b5ebc0a9cc34006c8 to your computer and use it in GitHub Desktop.
Docker disk exhaustion
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 | |
get_space_available() { | |
grep 'Data Space Available' <<< "${1}" | \ | |
sed -e 's/.*: //' | \ | |
xargs -I'{}' units '{}' "MB" -t | |
} | |
sudo docker pull ubuntu | |
i=0 | |
while true; do | |
date | |
echo "Starting ${i}" | |
container_name="dd-$i" | |
i=$((i+1)) | |
containers+=(${container_name}) | |
sudo timeout 1m docker run --name=${container_name} --detach ubuntu dd if=/dev/urandom of=sample.txt bs=64M count=1 iflag=fullblock | |
exitcode=$? | |
if [[ ${exitcode} -eq 124 ]]; then | |
echo "docker run is hanging" | |
exit 1 | |
fi | |
if [[ ${exitcode} -ne 0 ]]; then | |
echo "docker run failed, this could be because space is too low (and is a good thing)" | |
break | |
fi | |
containerexit=$(sudo timeout 5m docker wait ${container_name}) | |
exitcode=$? | |
date | |
if [[ ${exitcode} -eq 124 ]]; then | |
echo "docker wait ${container_name} took too long" | |
exit 1 | |
fi | |
info=$(sudo timeout 1m docker info) | |
if [[ $? -eq 124 ]]; then | |
echo "docker info is hanging" | |
exit 1 | |
fi | |
space=$(get_space_available "${info}") | |
echo "Space available: ${space}" | |
if [[ "${space}" == "0" ]]; then | |
echo "Space exhausted" | |
break | |
fi | |
done | |
sudo timeout 1m docker info | |
if [[ $? -eq 124 ]]; then | |
echo "docker info is hanging" | |
exit 1 | |
fi | |
echo "docker exhausted the disk without hanging" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment