Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fardjad/a83c30b9b744b9612d793666f28361a5 to your computer and use it in GitHub Desktop.
Save fardjad/a83c30b9b744b9612d793666f28361a5 to your computer and use it in GitHub Desktop.
[How to start Colima automatically on macOS] Instructions for starting Colima automatically on macOS similar to Docker Desktop #macos #colima #docker

⚠️ Note: Since the merge of the commit Homebrew/homebrew-core#149670, starting Colima is as easy as running brew services start colima. You can skip the following work-around.

Steps

  1. Create an executable script to run in foreground and manage colima:
cat <<-EOF | sudo tee /usr/local/bin/colima-start-fg
#!/bin/bash

export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

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
  sleep 5
done

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

sudo chmod +x /usr/local/bin/colima-start-fg
  1. Create a launchd agent to run colima automatically:
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>/usr/local/bin/colima-start-fg</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
  </dict>
</plist>
EOF

launchctl load -w $HOME/Library/LaunchAgents/com.github.abiosoft.colima.plist
@bpoland
Copy link

bpoland commented Aug 2, 2023

Thanks for this! One tweak for anyone using an M1/Apple Silicon that installed colima via Homebrew -- you'll need to add /opt/homebrew/bin to the PATH in step 1 in order for it to work :)

@cupofjoakim
Copy link

I'll just mention here for those without the knowhow that you might not have a LaunchAgents folder, in which case you'll get a no such file or directory error for the plist command.

If this is the case for you, just create the folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment