Skip to content

Instantly share code, notes, and snippets.

@dmcgowan
Created June 30, 2016 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmcgowan/f01445186e59d19381d3bc7ca0c5324c to your computer and use it in GitHub Desktop.
Save dmcgowan/f01445186e59d19381d3bc7ca0c5324c to your computer and use it in GitHub Desktop.
Test docker run on fresh device
#!/bin/env sh
# testrun.sh runs a docker container on a fresh device
# to test for errors mounting and running a container.
#
# Usage:
# sh testrun.sh <device> <storage driver> <image> [<run arg>, ...]
#
# How to use:
# $ fallocate -l 2GB testvolume
# $ device=$(sudo losetup -f --show ./testvolume)
# $ sudo mkfs -t xfs -m crc=0 -n ftype=0 -f $device
# $ sudo sh testrun.sh $device overlay ubuntu:latest /bin/echo "Works just fine!"
tmpdir=$(mktemp -d)
device=$1
graphdriver=$2
shift
shift
mount $device $tmpdir
echo "Mounted $device to $tmpdir"
echo "Starting docker engine using $graphdriver storage driver"
docker daemon -D -s $graphdriver -g $tmpdir > /tmp/dockertestlog.txt 2>&1 &
sleep 10
docker run $@
kill $(cat /var/run/docker.pid)
sleep 2
umount $tmpdir
rmdir $tmpdir
echo "Unmounted and remove $tmpdir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment