Skip to content

Instantly share code, notes, and snippets.

@lucablackwell
Created September 28, 2022 09:00
Show Gist options
  • Save lucablackwell/ac82c5a6e4b551aef8cefcf505d63e5c to your computer and use it in GitHub Desktop.
Save lucablackwell/ac82c5a6e4b551aef8cefcf505d63e5c to your computer and use it in GitHub Desktop.
Mac version of docker switch
#!/bin/bash
# Swaps local docker instances
# (I recommend making an alias to call the script)
# Directory names will need changing for your needs!
function start () {
# Change to the chosen directory
cd ~/PhpstormProjects/$1
# Start the chosen containers
docker compose up -d
}
function stop () {
# Change to the chosen directory
cd ~/PhpstormProjects/$1
# Start the Hub containers
docker compose down
}
function eval () {
# If chosen is already running
if grep -q $2 <<< $docker; then
echo --- $3 already running
exit
# If first other option is running
elif grep -q $5 <<< $docker; then
echo --- Stopping $6
stop $4
# If second other option is running
elif grep -q $7 <<< $docker; then
echo --- Stopping $9
stop $8
fi
echo --- Starting $3
start $1
}
# Assign the output of docker ps to a variable
docker=`docker ps`
case $1 in
'hub')
eval hub intranet2 Hub winchester winchester Winchester mcc mcc MyCompleteCoach
;;
'win')
eval winchester winchester Winchester hub intranet2 Hub mcc mcc MyCompleteCoach
;;
'mcc')
eval mcc mcc MyCompleteCoach hub intranet2 Hub winchester winchester Winchester
;;
'stop')
if grep -q 'Up' <<< $docker; then
# If Hub is running
if grep -q 'intranet2' <<< $docker; then
echo --- Hub found, stopping
stop hub
fi
# If Winchester is running
if grep -q 'winchester' <<< $docker; then
echo --- Winchester found, stopping
stop winchester
fi
# If MyCompleteCoach is running
if grep -q 'mcc' <<< $docker; then
echo --- MyCompleteCoach found, stopping
stop mcc
fi
else
echo --- Nothing to stop. Enter \"hub\", \"win\" or \"mcc\" to start
fi
;;
*)
echo --- Enter \"hub\", \"win\", \"mcc\" or \"stop\"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment