Using Lando as an alternative to Vagrant

Published by at 4th February 2018 12:12 am

Although Vagrant is very useful for ensuring consistency between development environments, it's quite demanding on system resources. Running a virtual machine introduces quite a bit of overhead, and it can be troublesome to provision.

This week I was introduced to Lando as an alternative to Vagrant. Rather than running a virtual machine like Vagrant does by default, Lando instead spins up Docker containers for the services you need, meaning it has considerably less overhead than Vagrant. It also includes presets for a number of frameworks and CMS's, including:

  • Drupal 7
  • Drupal 8
  • Wordpress
  • Laravel

Considering that Vagrant needs quite a bit of boilerplate to set up the server for different types of projects, this gives Lando an obvious advantage. The only issue I've had with it is that it's been unreliable when I've had to use it on Windows, which I don't do much anyway.

Getting started

Lando requires that you have Docker installed. Once that's done you can download and install it fro the website. Then you can run lando init to set it up:

1$ lando init
2? What recipe do you want to use? wordpress
3? Where is your webroot relative to the init destination? .
4? What do you want to call this app? wp-site
7Your app has been initialized!
9Go to the directory where your app was initialized and run
10`lando start` to get rolling.
12Check the LOCATION printed below if you are unsure where to go.
14Here are some vitals:
16 NAME wp-site
17 LOCATION /home/matthew/Projects/wp-site
18 RECIPE wordpress

Here I've chosen the wordpress recipe, in the current directory, with the name wp-site. This generates the following file as .lando.yml:

1name: wp-site
2recipe: wordpress
4 webroot: .

Then, if we run lando start, it will set up the required services:

1$ lando start
2landoproxyhyperion5000gandalfedition_proxy_1 is up-to-date
3Creating network "wpsite_default" with the default driver
4Creating volume "wpsite_appserver" with default driver
5Creating volume "wpsite_data" with default driver
6Creating volume "wpsite_data_database" with default driver
7Creating wpsite_appserver_1 ...
8Creating wpsite_database_1 ...
9Creating wpsite_database_1
10Creating wpsite_appserver_1 ... done
11 % Total % Received % Xferd Average Speed Time Time Time Current
12 Dload Upload Total Spent Left Speed
13100 4454k 100 4454k 0 0 3288k 0 0:00:01 0:00:01 --:--:-- 3290k
14OS: Linux 4.13.0-32-generic #35-Ubuntu SMP Thu Jan 25 09:13:46 UTC 2018 x86_64
16PHP binary: /usr/local/bin/php
17PHP version: 7.1.13
18php.ini used:
19WP-CLI root dir: phar://wp-cli.phar
20WP-CLI vendor dir: phar://wp-cli.phar/vendor
21WP_CLI phar path: /tmp
22WP-CLI packages dir:
23WP-CLI global config:
24WP-CLI project config:
25WP-CLI version: 1.5.0
29Your app has started up correctly.
30Here are some vitals:
32 APPSERVER URLS https://localhost:32802
33 http://localhost:32803

Note the APPSERVER URLS section - the site can be accessed locally via HTTP or HTTPS. For this recipe, it also installs WP CLI.

If we run docker ps, we can see that it's running three Docker containers:

22e920e152091 devwithlando/php:7.1-apache "/lando-entrypoint.s…" 16 minutes ago Up 16 minutes>80/tcp,>443/tcp wpsite_appserver_1
382ea60b1214f mysql:latest "/lando-entrypoint.s…" 16 minutes ago Up 16 minutes>3306/tcp wpsite_database_1
4e51d831199d7 traefik:1.3-alpine "/lando-entrypoint.s…" About an hour ago Up About an hour>80/tcp,>443/tcp,>8080/tcp landoproxyhyperion5000gandalfedition_proxy_1

Apache lives in one container, MySQL in another, while the third runs Traefik, a lightweight load balancer, which listens on port 80. Traefik does the work of redirecting HTTP requests to the right place.

As I've been unhappy with the amount of resources Vagrant uses for a while, and I usually run Ubuntu (making using Docker straightforward), I'm planning on using Lando extensively in future. It's lighter and faster to set up, and has sane defaults for most of the frameworks and CMS's I use regularly, making it generally quicker and easier to work with.