Last active
September 26, 2022 18:24
-
-
Save Gerst20051/bf1341448bd43f430761c1f8150fb1b7 to your computer and use it in GitHub Desktop.
Automate Docker Setup Script
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
#!/usr/bin/env sh | |
# ASCII: http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Docker%20Setup%20Script | |
# SOURCE: https://gist.github.com/Gerst20051/bf1341448bd43f430761c1f8150fb1b7 | |
function double_echo { | |
echo && echo | |
} | |
function newline { | |
echo | |
} | |
bold=$(tput bold) | |
normal=$(tput sgr0) | |
function init { | |
echo | |
print_purpose_header && double_echo | |
confirm_continue && double_echo | |
install_docker && double_echo | |
start_docker && double_echo | |
confirm_docker_helper && double_echo | |
confirm_docker_enable_start && double_echo | |
confirm_docker_memory && double_echo | |
print_finished_header && double_echo | |
} | |
function print_purpose_header { | |
echo '________ __ _________ __ _________ .__ __ ' | |
echo '\______ \ ____ ____ | | __ ___________ / _____/ _____/ |_ __ ________ / _____/ ___________|__|______/ |_ ' | |
echo ' | | \ / _ \_/ ___\| |/ // __ \_ __ \ \_____ \_/ __ \ __\ | \____ \ \_____ \_/ ___\_ __ \ \____ \ __\' | |
echo ' | ` ( <_> ) \___| <\ ___/| | \/ / \ ___/| | | | / |_> > / \ \___| | \/ | |_> > | ' | |
echo '/_______ /\____/ \___ >__|_ \\___ >__| /_______ /\___ >__| |____/| __/ /_______ /\___ >__| |__| __/|__| ' | |
echo ' \/ \/ \/ \/ \/ \/ |__| \/ \/ |__| ' | |
} | |
function confirm_continue { | |
echo '_________ _____.__ _________ __ .__ ' | |
echo '\_ ___ \ ____ _____/ ____\__|______ _____ \_ ___ \ ____ _____/ |_|__| ____ __ __ ____ ' | |
echo '/ \ \/ / _ \ / \ __\| \_ __ \/ \ / \ \/ / _ \ / \ __\ |/ \| | \_/ __ \ ' | |
echo '\ \___( <_> ) | \ | | || | \/ Y Y \ \ \___( <_> ) | \ | | | | \ | /\ ___/ ' | |
echo ' \______ /\____/|___| /__| |__||__| |__|_| / \______ /\____/|___| /__| |__|___| /____/ \___ >' | |
echo ' \/ \/ \/ \/ \/ \/ \/ ' | |
double_echo | |
local CONTINUE_CONFIRM='' | |
until [ "$CONTINUE_CONFIRM" = 'run' ]; do | |
read -p 'type "run" to continue: ' CONTINUE_CONFIRM | |
done | |
} | |
function install_docker { | |
echo '.___ __ .__ .__ .__ ________ __ ' | |
echo '| | ____ _______/ |______ | | | | |__| ____ ____ \______ \ ____ ____ | | __ ___________ ' | |
echo '| |/ \ / ___/\ __\__ \ | | | | | |/ \ / ___\ | | \ / _ \_/ ___\| |/ // __ \_ __ \' | |
echo '| | | \\___ \ | | / __ \| |_| |_| | | \/ /_/ > | ` ( <_> ) \___| <\ ___/| | \/' | |
echo '|___|___| /____ > |__| (____ /____/____/__|___| /\___ / /_______ /\____/ \___ >__|_ \\___ >__| ' | |
echo ' \/ \/ \/ \//_____/ \/ \/ \/ \/ ' | |
double_echo | |
if [ -x /Applications/Docker.app ]; then | |
echo "docker is ${bold}already${normal} installed" | |
else | |
echo '[$]> brew install --cask docker' | |
double_echo | |
brew install --cask docker | |
fi | |
} | |
function start_docker { | |
echo ' _________ __ __ .__ ________ __ ' | |
echo ' / _____// |______ ________/ |_|__| ____ ____ \______ \ ____ ____ | | __ ___________ ' | |
echo ' \_____ \\ __\__ \\_ __ \ __\ |/ \ / ___\ | | \ / _ \_/ ___\| |/ // __ \_ __ \' | |
echo ' / \| | / __ \| | \/| | | | | \/ /_/ > | ` ( <_> ) \___| <\ ___/| | \/' | |
echo '/_______ /|__| (____ /__| |__| |__|___| /\___ / /_______ /\____/ \___ >__|_ \\___ >__| ' | |
echo ' \/ \/ \//_____/ \/ \/ \/ \/ ' | |
double_echo | |
echo '[$]> open -a Docker' | |
newline | |
echo '[$]> docker stats --no-stream' | |
double_echo | |
if (! docker stats --no-stream &>/dev/null); then | |
# NOTE: the --hide and/or --background flags may no longer work | |
# [$]> open --hide --background -a Docker | |
open -a Docker | |
iteration=1 | |
sleep_seconds=6 | |
seconds_to_wait=120 # 2 minutes | |
max_iterations=$((seconds_to_wait / sleep_seconds)) # 20 iterations | |
while [[ $iteration -le $max_iterations ]] && (! docker stats --no-stream &>/dev/null); do | |
echo "$iteration/$max_iterations waiting for docker to launch..." | |
sleep $sleep_seconds | |
((iteration++)) | |
done | |
if (! docker stats --no-stream &>/dev/null); then | |
double_echo | |
open -a Docker # we can attempt to open docker again | |
while (! docker stats --no-stream &>/dev/null); do | |
echo "you must ${bold}manually${normal} open docker to continue..." | |
sleep $sleep_seconds | |
done | |
fi | |
double_echo | |
echo "docker is ${bold}now${normal} started" | |
else | |
echo "docker is ${bold}already${normal} started" | |
fi | |
} | |
function confirm_docker_helper { | |
echo '.___ __ .__ .__ ________ __ ___ ___ .__ ' | |
echo '| | ____ _______/ |______ | | | | \______ \ ____ ____ | | __ ___________ / | \ ____ | | ______ ___________ ' | |
echo '| |/ \ / ___/\ __\__ \ | | | | | | \ / _ \_/ ___\| |/ // __ \_ __ \ / ~ \_/ __ \| | \____ \_/ __ \_ __ \' | |
echo '| | | \\___ \ | | / __ \| |_| |__ | ` ( <_> ) \___| <\ ___/| | \/ \ Y /\ ___/| |_| |_> > ___/| | \/' | |
echo '|___|___| /____ > |__| (____ /____/____/ /_______ /\____/ \___ >__|_ \\___ >__| \___|_ / \___ >____/ __/ \___ >__| ' | |
echo ' \/ \/ \/ \/ \/ \/ \/ \/ \/ |__| \/ ' | |
double_echo | |
echo 'confirm that the docker helper tool has finished installing' | |
double_echo | |
echo 'when you open up the docker preferences you should be prompted for your machine password to install the helper tool' | |
echo 'docker desktop needs privileged access to install its networking components and links to the docker apps' | |
double_echo | |
local DOCKER_HELPER_INSTALL_CONFIRM='' | |
until [ "$DOCKER_HELPER_INSTALL_CONFIRM" = 'docker' ]; do | |
read -p 'type "docker" to acknowledge: ' DOCKER_HELPER_INSTALL_CONFIRM | |
done | |
# NOTE: Need To Open Up The Docker Preferences To Install Helper | |
# Docker needs to install a new helper tool. | |
# Docker Desktop needs privileged access to install its networking components and links to the Docker apps. | |
# You will be asked for your password. | |
} | |
function confirm_docker_enable_start { | |
echo '________ __ ___________ ___. .__ _________ __ __ ' | |
echo '\______ \ ____ ____ | | __ ___________ \_ _____/ ____ _____ \_ |__ | | ____ / _____// |______ ________/ |_ ' | |
echo ' | | \ / _ \_/ ___\| |/ // __ \_ __ \ | __)_ / \\__ \ | __ \| | _/ __ \ \_____ \\ __\__ \\_ __ \ __\' | |
echo ' | ` ( <_> ) \___| <\ ___/| | \/ | \ | \/ __ \| \_\ \ |_\ ___/ / \| | / __ \| | \/| | ' | |
echo '/_______ /\____/ \___ >__|_ \\___ >__| /_______ /___| (____ /___ /____/\___ > /_______ /|__| (____ /__| |__| ' | |
echo ' \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ ' | |
double_echo | |
echo 'the docker daemon needs to be running for docker compose to work' | |
echo 'go to docker preferences -> general -> enable "start docker desktop when you log in" -> click apply & restart button' | |
double_echo | |
local DOCKER_ENABLE_START_CONFIRM='' | |
until [ "$DOCKER_ENABLE_START_CONFIRM" = 'docker' ]; do | |
read -p 'type "docker" to acknowledge: ' DOCKER_ENABLE_START_CONFIRM | |
done | |
} | |
function confirm_docker_memory { | |
echo '________ __ _____ ' | |
echo '\______ \ ____ ____ | | __ ___________ / \ ____ _____ ___________ ___.__.' | |
echo ' | | \ / _ \_/ ___\| |/ // __ \_ __ \ / \ / \_/ __ \ / \ / _ \_ __ < | |' | |
echo ' | ` ( <_> ) \___| <\ ___/| | \/ / Y \ ___/| Y Y ( <_> ) | \/\___ |' | |
echo '/_______ /\____/ \___ >__|_ \\___ >__| \____|__ /\___ >__|_| /\____/|__| / ____|' | |
echo ' \/ \/ \/ \/ \/ \/ \/ \/ ' | |
double_echo | |
echo 'the containers can run out of memory so it is recommended to increase it from 2GB to 4GB' | |
echo 'go to docker preferences -> resources -> memory -> 4GB+ -> click apply & restart button' | |
double_echo | |
local DOCKER_MEMORY_CONFIRM='' | |
until [ "$DOCKER_MEMORY_CONFIRM" = 'docker' ]; do | |
read -p 'type "docker" to acknowledge: ' DOCKER_MEMORY_CONFIRM | |
done | |
} | |
function print_finished_header { | |
echo '___________.__ .__ .__ .___ ________ __ _________ __ ' | |
echo '\_ _____/|__| ____ |__| _____| |__ ____ __| _/ \______ \ ____ ____ | | __ ___________ / _____/ _____/ |_ __ ________ ' | |
echo ' | __) | |/ \| |/ ___/ | \_/ __ \ / __ | | | \ / _ \_/ ___\| |/ // __ \_ __ \ \_____ \_/ __ \ __\ | \____ \ ' | |
echo ' | \ | | | \ |\___ \| Y \ ___// /_/ | | ` ( <_> ) \___| <\ ___/| | \/ / \ ___/| | | | / |_> >' | |
echo ' \___ / |__|___| /__/____ >___| /\___ >____ | /_______ /\____/ \___ >__|_ \\___ >__| /_______ /\___ >__| |____/| __/ ' | |
echo ' \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ |__| ' | |
} | |
init |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Command To Run The Docker Setup Script
[$]> /bin/bash -c "$(curl -s https://api.github.com/gists/bf1341448bd43f430761c1f8150fb1b7 | jq -r '.files["docker-setup.sh"].content')"