Last active
June 15, 2022 09:37
-
-
Save TomK/ff6ad7a367a1fc0c6c0739cf805b4e27 to your computer and use it in GitHub Desktop.
installs busybox in a scratch container if sh is not available
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 | |
TARGET=$1 | |
if [ -z "$TARGET" ]; then | |
echo "no target container specified" | |
exit 1 | |
fi | |
docker container inspect $TARGET >/dev/null | |
if [ $? -ne 0 ]; then | |
echo "target container does not exist" | |
exit 1 | |
fi | |
docker exec -it $TARGET sh -c "exit" >/dev/null | |
if [ $? -ne 0 ]; then | |
BUSY=$(docker run -d busybox:latest sleep 100) | |
docker cp $BUSY:/bin/busybox /tmp/busybox | |
docker kill $BUSY | |
docker cp /tmp/busybox $TARGET:/busybox | |
docker exec -it $TARGET /busybox sh -c ' | |
export PATH="/busybin:$PATH" | |
/busybox mkdir /busybin | |
/busybox --install /busybin | |
sh' | |
else | |
docker exec -it $TARGET sh | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment