Last active
February 9, 2025 22:58
-
-
Save mikesparr/d4abe44d0863c01939a102ba0e31cf94 to your computer and use it in GitHub Desktop.
Helper script to replace Docker Desktop for Mac with Colima and test networking
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/env bash | |
##################################################################### | |
# REMOVE DOCKER DESKTOP FOR MAC (OPTIONAL: IF INSTALLED) | |
##################################################################### | |
echo "" | |
echo "Removing Docker Desktop for Mac..." | |
# 1. make sure docker running | |
sudo launchctl start com.docker.docker | |
# 2. clean up while still running | |
docker rmi -f $(docker images -a -q) | |
docker rm -f $(docker ps -a -q) | |
docker volume rm $(docker volume ls -q) | |
# 2. then turn off Docker Desktop for Mac | |
sudo launchctl stop com.docker.docker | |
# 3. then open Finder > Applications and "Move to Trash" and "Empty Trash" for "Docker" app | |
sudo rm -rf /Applications/Docker | |
# 4. remove leftover files | |
paths=( | |
"~/Library/Cookies/com.docker.docker.binarycookies" | |
"~/Library/Logs/Docker Desktop" | |
"~/Library/Application Support/Docker Desktop" | |
"~/Library/Caches/com.docker.docker" | |
"~/Library/Group Containers/group.com.docker" | |
"~/Library/Saved Application State/com.electron.docker-frontend.savedState" | |
"/Library/PrivilegedHelperTools/com.docker.vmnetd" | |
"/Library/LaunchDaemons/com.docker.vmnetd.plist" | |
"/usr/local/lib/docker" | |
"~/.docker" | |
) | |
for path in "${paths[@]}"; do | |
eval rm -rf $path | |
echo "Deleted: $path" | |
done | |
echo "" | |
echo "DONE." | |
##################################################################### | |
# INSTALL COLIMA WITH BUILDX, DOCKER, KUBECTL | |
##################################################################### | |
echo "" | |
echo "Installing Colima ..." | |
# 1. install colima | |
brew install colima | |
# 2. install docker | |
brew install docker | |
# 3. install buildx | |
brew install docker-buildx | |
# 4. install kubectl | |
brew install kubectl | |
# link buildx | |
mkdir -p ~/.docker/cli-plugins/ | |
ln -sfn $(which docker-buildx) ~/.docker/cli-plugins/docker-buildx | |
# start colima | |
brew services start colima | |
# wait a minute or two for vm and container runtime then test | |
sleep 30 | |
docker images | |
# hooray! | |
echo "" | |
echo "DONE." | |
##################################################################### | |
# ENSURE CONTAINERS CAN REACH HOST NETWORK (OPTIONAL) | |
##################################################################### | |
echo "" | |
echo "Testing networking ..." | |
# print out bridge network gateway IP | |
docker network inspect bridge -f '{{range .IPAM.Config}}{{.Gateway}}{{end}}' | |
# add flag for container run to point to host via DNS and print IP address | |
docker run -it --rm --add-host=host.docker.internal:host-gateway busybox ping host.docker.internal | |
# test databases | |
docker run -it --rm --add-host=host.docker.internal:host-gateway busybox nc -zv host.docker.internal 5432 # postgres | |
docker run -it --rm --add-host=host.docker.internal:host-gateway busybox nc -zv host.docker.internal 6379 # redis | |
echo "" | |
echo "DONE." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment