Last active
August 2, 2019 13:10
-
-
Save granthenke/7895c253450fb6755c78b7eedab2035b to your computer and use it in GitHub Desktop.
Turtles docker image. Docker containers inside of docker containers recursively. A case of because I can, not because I should...
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
FROM docker:dind as turtles | |
VOLUME ["/image"] | |
COPY ./turtles.sh /tmp | |
WORKDIR /tmp | |
ENTRYPOINT ["./turtles.sh"] | |
CMD ["turtle"] |
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 | |
docker build -t granthenke/turtles:latest . | |
# Setup: Save the image so it can be mounted as a volume | |
# This prevents downloading the image at each level. | |
mkdir image | |
docker save -o image/turtles.docker granthenke/turtles:latest | |
chmod 777 image/turtles.docker | |
# Run the turtles image and pass how deep you want to go... | |
docker run -it --rm --privileged -v $(pwd)/image:/image granthenke/turtles:latest turtle 3 |
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/sh | |
if [ "$1" = "turtle" ]; then | |
END=${2:-1} | |
LAST=${3:-0} | |
CUR=$(($LAST + 1)) | |
SIZE=${#CUR} | |
LEFT=$(((6-$SIZE)/2)) | |
RIGHT=$((6-($LEFT+$SIZE))) | |
printf " _____ ____\n" | |
printf "/ \ | o |\n" | |
printf "| " | |
printf "%*s%s%-*s" $LEFT "" "$CUR" $RIGHT "" | |
printf "|/ ___\|\n" | |
printf "|_________/\n" | |
printf "|_|_| |_|_|\n" | |
if [ $END -gt $CUR ]; then | |
# Start the docker daemon. | |
dockerd-entrypoint.sh >/dev/null 2>&1 & | |
# Loop until the docker daemon is ready. | |
until docker version >/dev/null 2>&1 | |
do | |
sleep 1 | |
done | |
# Copy the image into the container from the volume so it can be mounted again. | |
mkdir /cimage | |
cp /image/turtles.docker /cimage/turtles.docker | |
# Go deeper. | |
docker load -q -i /cimage/turtles.docker >/dev/null 2>&1 | |
docker run -it --rm --privileged -v /cimage:/image -e LOG=file granthenke/turtles:latest turtle $END $CUR | |
fi | |
exit 0 | |
fi | |
# Support calling anything else in the container. | |
exec "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment