Skip to content

Instantly share code, notes, and snippets.

@violetyk
Created August 14, 2015 10:21
Show Gist options
  • Save violetyk/afd8a215ae643f0dcbac to your computer and use it in GitHub Desktop.
Save violetyk/afd8a215ae643f0dcbac to your computer and use it in GitHub Desktop.
docker run をコンテナの並列実行
#!/bin/bash
DIRS=("/bin" "/etc" "/usr") # SUCCESS
# DIRS=("/bin" "/etc" "/usr" "/hogehoge") # FAILURE
IDS=""
for D in ${DIRS[*]}; do
IDS=$IDS" `docker run -d ubuntu du -sh $D`"
done
echo "containers : $IDS"
# 各コンテナの結果を集める
RESULT=0
for S in `time docker wait $IDS`; do
RESULT=`expr $RESULT + $S`
done
# 失敗してたら各コンテナのログを表示
if [ $RESULT -eq 0 ]; then
echo "SUCCESS!"
exit 0
else
for c in ${IDS[*]}; do
docker logs $c
done
echo "FAILURE!!"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment