2024-10-05 14:50:04 +03:00

42 lines
646 B
Bash
Executable File

#!/bin/bash
if [[ "$1" == "docker-cli-plugin-metadata" ]]; then
cat << HERE
{
"SchemaVersion": "0.1.0",
"Vendor": "Thek4n",
"Version": "0.1.0",
"ShortDescription": "Open interactive bash in container"
}
HERE
exit
fi
usage() {
cat <<EOF
Usage: docker shell CONTAINER
Enter the container shell (bash or sh)
EOF
}
shift
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
usage
exit 0
fi
readonly CONTAINER="$1"
if [ -z "$CONTAINER" ]; then
echo "Error: Container was not specified"
exit 1
fi
set -e
docker exec -it "$CONTAINER" \
/bin/sh -c "[ -e /bin/bash ] && exec /bin/bash || exec /bin/sh"
exit 0