Please wait...
Drupal 8, Docker, Lando

Drupal 8 - Easy Local Containerization With Lando

Back in the day a local development set-up for Drupal was simple:  Clone your codebase with git (or the version control program of your choice), download and import your database, and optionally rsync your files directory.  A little drush cc all, a quick edit to /etc/hosts and presto!  Environment up, and ready to dev.  Great, problem solved.

Well, no… There were of course, some problems with this approach.  Namely, the inevitable “It works on my local!” situation in which a new feature or bug fix works perfectly on your local environment set up, but not on the development, staging or production server.  Similarly, the fact that it worked on your machine didn’t necessarily mean that it worked on other team members’ machines.  This is a big problem when sharing the work load across the whole team.  You can imagine the frustration and the productivity loss if I clone your branch to add some work to it, and it breaks my development environment completely.  

In order to solve these problems, we turned to virtualization.  Using virtualization software like VMWare, or VirtualBox, one could easily set up a virtual linux server to run one’s local environment on.  More importantly, these virtual machine configurations could be made to mirror production environments and could be shared across teams so that each developer on the team has the exact same setup as the production server.  No more “It works on my machine” excuses!  Great, problem solved.

Well, no…  These VMs are slow.  Slow to boot, difficult to maintain and depending on how complex your server architecture was, they could be painfully slow to run.  This less than stellar performance really negatively impacted productivity.  If it takes 15 - 20 seconds for a page to load locally, you might forget what it was you were working on by the time the page loads!

I suppose it was sometime in 2014 that I first heard about Docker.  Docker, as we all know now, is a containerization engine.  If you don’t know, what Docker allows us to do is to package and deploy software applications as lightweight, super-portable fully self-sufficient containers that will run pretty much anywhere.  Hooray!  Problem solved.

Well no… The issue with Docker is that it can be a steep learning curve for developers who don't specialize in dev-ops.  If you’re like me, and you’d rather spend your time writing software than configuring environments in which to run and develop that software, then Docker can be very frustrating.  It can be difficult for many developers (including this one!) to grasp much beyond the basics.  In the enterprise, Docker set-ups can be massively complex.  In fact many organizations are now looking for Docker specialists in order to let devs do what devs do best without worrying about environment setups.  (A quick search for Docker on GlassDoor yields loads of very high-paying open positions.)  That's great if you work for a massive enterprise company with the budget for a few full-time dev-ops engineers, but what if that's not the case?

In order to solve this problem, a whole slew of 'Docker for Drupal — made easy’ applications have sprung up.  There’s DDEV (which — full disclosure — the sum total of my experience with DDEV is that I’m aware of its existence), Docksal and Lando.  There are probably others too, but these are the three that I’m aware of.  I use Docksal quite a bit.  In my experience, it can be frustrating.  Performance is not great — IMHO, nearly as bad as a VM.  I always thought this was due to problems with Docker running on a mac, but I’ve recently discovered Lando, and so far, color me impressed.  It makes containerizing your Drupal site pretty simple.  Follow these steps:

  • Install lando -

  • git clone your Drupal site (or start a new Drupal site) locally

  • cd into the cloned directory

  • lando init

  • Now press the down arrow to select ‘Drupal 8'

  • Type in your web root (./web if you’ve installed Drupal via composer)

  • Give a name to your Lando app

  • Now add and commit your .lando.yml file

  • lando start - Save the output of this, as you’ll need it soon

  • lando info - Save the output of this, as you’ll need it soon

  • lando composer install - This should run the composer install command.  If you get an error here, just run composer install manually without the ‘lando'

  • Now visit one of the urls that were output by the ‘lando start’ command.

  • You should see the Drupal install screen

  • Click through the steps to install Drupal 8

  • When you get to the database section, take a look at the output from ‘lando info’.  Use the ‘internal connection’ database info.  For me, it was database name: drupal8, database username: drupal8, database password: drupal8, and host: database.

  • Once the install is completed, if this is a new Drupal8 site, you’re done!

  • If you have a pre-existing site that you want a local install of, then download a dump of your database.  Make sure you put this database dump file somewhere within your app directory (I put mine in my ‘web’ directory)

  • lando db-import database-dump.sql

  • This will overwrite the vanilla drupal8 database that was created during the install process.

  • I had a theming issue after this, but I found the solution here:

  • If you have configuration that you need locally, export the config and import it locally

That’s it. Now you have a containerized local set-up of your Drupal 8 site.