Skip to content

Instantly share code, notes, and snippets.

@flaviodelgrosso
Last active November 20, 2024 10:38
Show Gist options
  • Save flaviodelgrosso/3b244d9f918243abacb41a3dd8168700 to your computer and use it in GitHub Desktop.
Save flaviodelgrosso/3b244d9f918243abacb41a3dd8168700 to your computer and use it in GitHub Desktop.

Install Docker and Colima on macOS

brew install docker docker-compose docker-buildx
brew install colima

Connect symbolic link of docker-compose and docker-buildx

mkdir ~/.docker/cli-plugins
ln -sfn $(brew --prefix)/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose
ln -sfn $(brew --prefix)/opt/docker-buildx/bin/docker-buildx ~/.docker/cli-plugins/docker-buildx

Add in your shell:

export DOCKER_HOST="unix://$HOME/.colima/default/docker.sock"

or

export DOCKER_HOST="$(docker context inspect --format '{{ .Endpoints.docker.Host }}')"

Run Colima

colima start --cpu 4 --memory 8 --mount-type virtiofs --vm-type vz --mount-inotify

Start Colima as agent on startup

Create the script

cat <<-EOF | sudo tee /opt/homebrew/bin/colima-agent
#!/bin/bash

export PATH="/opt/homebrew/bin"

function shutdown() {
  colima stop
  exit 0
}

trap shutdown SIGTERM
trap shutdown SIGINT

# wait until colima is running
while true; do
  colima status &>/dev/null
  if [[ \$? -eq 0 ]]; then
    break;
  fi

  colima start --memory 4 --mount-type virtiofs --vm-type vz --mount-inotify
  sleep 5
done

tail -f /dev/null &
wait \$!
EOF

sudo chmod +x /opt/homebrew/bin/colima-agent

Create the launchd

cat > $HOME/Library/LaunchAgents/com.github.abiosoft.colima.plist <<-EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>com.github.abiosoft.colima</string>
    <key>Program</key>
    <string>/opt/homebrew/bin/colima-agent</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
  </dict>
</plist>
EOF

launchctl load -w $HOME/Library/LaunchAgents/com.github.abiosoft.colima.plist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment