Using Lando

What is Lando?

Lego Lando

Agile Collective uses the Lando project to manage the various environments needed to easily host and develop web sites locally on a computer.

Lando is a wrapper around Docker and provides a set of commands to interact with Docker containers.

Docker allows us to have containers configured for each of the tools or applications we need to host a web site. These include containers for a web server (Apache or NGINX), a database (MySQL, MariaDB etc), front end tools (gulp, node, npm etc). With these Docker containers we no longer have to install and maintain different versions of tools, like PHP, composer or node, on our host computer which simplifies and unifies our environments, in turn making them easier to use and support.

Lando makes it much easier to work with Docker as you'll only need to remember around four commands to manage your project and it allows you to run commands like drush, composer or gulp from your host environment outside of containers.

Installing Lando

To install Lando on your host machine please follow the instructions for your operating system:

You will need to install Docker as part of the install process and it might ask you to log into Docker Hub. You do not need to do this and can safely ignore this step.

Using Lando

Start Lando

It is best to start Lando while in the git root.

To start Lando run the following:

lando start

Once it finishes you will see something like the following output:

BOOMSHAKALAKA!!!

Your app has started up correctly.
Here are some vitals:

 NAME            projectname
 LOCATION        /Users/tanc/Sites/projectname
 SERVICES        appserver, database, mailhog, node
 APPSERVER URLS  https://localhost:32822
                 http://localhost:32823
                 http://projectname.lndo.site
                 https://projectname.lndo.site
 MAILHOG URLS    http://localhost:32819
                 http://mailhog.projectname.lndo.site
                 https://mailhog.projectname.lndo.site

It may take some time for Lando to completely bring up your environment the first time you run it as it needs to pull some large images off the web and store them locally. These images represent the containers Lando is using to run a webserver, nodejs etc.

Stop Lando

To stop the containers you can run the following from the gitroot of the project you want to stop:

lando stop

You can run multiple projects at once as Lando will avoid port clashes by randomising external ports on your host machine. It is probably wise to get in the habit of stopping a project before working on a new one to keep your system resources in check.

Close Lando down completely (free up port 80)

As Lando runs a server on port 80 which it uses to proxy requests back to the various containers you may find you need to completely shut down Lando so you can work on another dev environment that uses port 80. To do this you issue the poweroff command:

lando poweroff

You can also stop/quit the Docker app (MacOS users will notice it in the menu bar at the top of the screen). This is safe to do and will close down all active sites. When you next open Docker (MacOS users will note it is an application in /Applications) you will need to fire up your project again with lando start

Import a database

To manually import a database (not sync it with drush) you will need to temporarily place it within your project directory (so that it is available within the containers) and run the following command:

lando db-import mydatabase.sql

You should delete (or move out of the project) the sql file after the import completes.

See full documentation here.

Using Drush

You can issue drush commands as you usually would but prefix them with lando first. For example, to rebuild caches:

lando drush cr

Theming

All the front end tooling you need should be included in the nodejs container, started and configured when you bring Lando up on this project. You can then run the usual commands by prefixing them with Lando first, for example:

lando npm start

More details can be found in the theming section of these docs.

Last updated: