/home/duker Speed up Lando with Colima in MacOS

Speed up Lando with Colima in MacOS

Warning: after this process you'll need to rebuild any lando projects that you want to use. If you have any information in previously built Lando projects you need to fetch you should do so before making the changes in the post but you can also: undo the changes to Lando's config.yml file to regain have access to your preexisting projects again.

brew install colima docker
colima start --cpu 4 --memory 6 --disk 100 --vm-type=qemu --mount-type=sshfs --dns=1.1.1.1

Once Colima is running check that your docker command uses it as a default backend

docker context ls | grep colima
colima *  moby colima unix:///Users/duker/.colima/default/docker.sock

If you see the * next to colima you are ready to go forward, otherwise change docker to use colima as a backend, docker context will give you some help on that.

We need to configure Lando to use the port and socket from colima. The socket we can get from the previously ran command. To get the port we need to get a little more creative. We know that colima uses qemu for the VM it runs so we can list all processes listening on ports with

lsof -i | grep LISTEN | grep qemu
qemu-syst 44196 duker   25u  IPv4 0x567251ae0f9e6083      0t0  TCP localhost:53590 (LISTEN)

The problem with this approach is that if you have more than one qemu VM running you wont be able to tell them appart, in that case you can do the right thing and get the port number from colima's ssh config with

❯ colima ssh-config | grep Port
  Port 53590

Now that we know our socket (/Users/duker/.colima/default/docker.sock) and port number (53590) we can setup Lando to use the colima VM instead of Docker desktop for its containers, add the following section to your ~/.lando/config.yml:

engineConfig:
  host: 127.0.0.1
  port: 53590
  socketPath: /Users/duker/.colima/default/docker.sock

After that step if all went well you can start using lando normally.

Page load comparisons

Some small benchmarks, each one was ran with no browser cache and using the Page Load Time Chrome extension on Brave.

The tests were ran on a Mac Studio 2022 with M1 Max and 64 GB of ram.

URL Page load time Cached? Backend
http://history-channel.lndo.site/ 11.9s No Docker
http://history-channel.lndo.site/ 1.84s Yes Docker
http://history-channel.lndo.site/ 9.10s No Colima
http://history-channel.lndo.site/ 1.60s Yes Colima
http://laemmle.lndo.site/ 6.07s No Docker
http://laemmle.lndo.site/ 1.64s Yes Docker
http://laemmle.lndo.site/ 7.45s No Colima
http://laemmle.lndo.site/ 2.20s Yes Colima

Installing lando inside Colima

sudo apk add nodejs yarn docker-compose
git clone https://github.com/lando/cli.git lando-cli
cd lando-cli && yarn
sudo ln -s $(pwd)/bin/lando.js /usr/local/bin/lando.dev

Installing nvm

cd && touch .profile
sudo apk add --no-cache libstdc++ coreutils curl bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash
echo "export NVM_NODEJS_ORG_MIRROR=https://unofficial-builds.nodejs.org/download/release" >> .profile
echo "nvm_get_arch() { nvm_echo \"x64-musl\"; }" >> .profile
source .profile