brew services start colima
. You can skip the following work-around.
- 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
- 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
@tj-smith47 No problem :)
It seems like
colima
in your case is sort of a dependency in a more complex setup.So, my initial thought/reaction is, what does your script do? Does it really need to be aware of the whole machinery (i.e. Colima, OrbStack, Docker Desktop, etc.) that runs the Docker Engine?
For use-cases such as running containers at startup, you can set a restart-policy for your containers.
If your script really depends on Docker (and for example needs the docker socket), you could wait/retry until your docker command succeeds (or the exit code of
docker info
is 0).If your script really needs to be aware of Colima, you could do something like this:
Also, kind of unrelated but noteworthy: at some point Colima changed the default VM type to
qemu
. QEMU has better compatibility but it can be slower than the native macOS virtualization framework (vz
). So you might want to play around with the options (runcolima start --edit
to edit the VM config) to find the optimal setup for your hardware.