My main driver in WSL2 is usually Alpine, but I’ve initially encountered some issues with installing Lando there. Alpine is not for the weak! Instead I am going to use Ubuntu (18.04) in WSL2, and install Lando there.
- Lando: Development environment centered around Docker and Docker Compose.
- Lando releases page: You can find the latest releases here.
- Latest lando release: v3.0.26
- Getting started with Lando.
- Windows Subsystem for Linux, version 2 (also known as WSL2).
- Docker for Windows, using the WSL2 backend.
- Ubuntu for WSL.
- Docker client installed and configured inside your WSL distro. You can read some of my stories for that here, here, and here.
Back in Lando Github issue #2781, some users were complaining how Docker Desktop automatically updates to the latest version, sometimes breaking Lando integration.
For context, when you first install Lando, Lando installs Docker Desktop for you. But that’s not all, Lando installs a specific version of Docker Desktop, a.k.a. not the latest.
As a person that has been working with containers 100% since at least 2017 I’ve always run the latest version of Docker Desktop locally to get the latest features. Having someone tell me to run an older version of DD for me would be a non-starter, and so today I was fixin’ to try and run Lando with my own version of Docker Desktop and not the old one installed my Lando.
TL;DR: It’s possible to use the latest Docker Desktop (3.2.x) with Lando on WSL2.
Install Lando from Github
First off, I assume that you have the latest Docker for Windows installed, along with WSL2, and in this case Ubuntu 18.04 or similar version.
Installing the Lando package, and ignore the Docker dependency in the process (Docker for Windows is already installed):
Confirm that you can Lando without any errors or warnings popping up:
As you can see, the
.deb package has installed Lando into the directory
Fire Up Lando
Create an example Lando stack
Examples can be taken from here.
Start our hello world example:
lando start seems to have completed without any major errors or warnings:
A warning due to the HTTPS certificate not being trusted shows up, but I click on Advanced -> Proceed to localhost.
The results is the following:
There is nothing present in the Apache web server, because Lando did not install Drupal.
Open Docker Desktop and exec into the Lando appserver container:
By clicking on the CLI button that throws you into an interactive shell of the appserver container:
There we can run a couple of diagnostics and confirm that the directory is indeed empty:
However, you can see a lonely .lando.yml file. That’s because that file got mounted from the WSL directory /home/wsl/drupal1 into the /app path in the container.
Installing Drupal with Composer
First confirm that Composer is installed in the container and it’s version:
Installing Drupal with Composer has been covered like a beaten dead horse everywhere else in the webs, so need not I got into detail. But the official documents for installing Drupal w/ Composer are here.
The template for Drupal 8/9 is:
composer create-project drupal/recommended-project my_site_name_dir
In my case I want to install to the current directory, because that’s already mounted by Lando from WSL into the Docker container, and that’s where Apache is looking for an index.php:
composer create-project drupal/recommended-project .
Compose does not let me install the latest Drupal version (9.x) because the Drupal recipe I used in my
.lando.yml installs PHP 7.3.x or greater, and the Lando Drupal recipe uses PHP 7.2.34. Here’s the complaint from Composer:
Cleanup any artifacts and re-try Drupal install with older version:
This time the Composer installer has a little more luck:
composer create-project drupal/recommended-project:8.x .
And installs the latest version of Drupal 8.x, in this case version 8.9.13:
Here are the results:
Now if I revisit the URL Lando gave me for my app, I get some contents:
And if I click on
web, I get a Drupal install page:
Running the Drupal database installer
When you exec into the Lando appserver container, you are exec’d in as root. The Apache server running inside the container expects files to be owned by www-data. If you install Drupal with Composer using root like I did, Drupal is not going to be able to write any initial directories it needs.
The easiest way to solve that is to
chown the whole app directory into
After doing that and refreshing the Drupal installer, the verify requirements page has automatically gone away (meaning Drupal was able to create any setup files it needed inside the container). Now I am presented with the Database setup page:
Configuring the database
TBH I don’t know what the database credentials are. And since I’m a developer that obviously means I’m never going to read the fine manual, hashtag #RTFM.
So I just do a good ‘ol exec into the MySQL container and do some investigation:
Bingo! Lando set ups the database with the user root, and no password (you can see here that using password root failed):
As part of the Lando drupal recipe, it seems that a database named
drupal7 was created. Luckily that’s how far Lando went, and the
drupal7 database is empty, meaning that we can use it for our Drupal install.
Using Docker for Windows, I can inspect the database container created by Lando, and see some useful environment variables that probably indicate what parameters I can use for setting up Drupal:
Of interest here are four environment variables:
MYSQL_DATABASE: The name of the database to use for Drupal.
MYSQL_PASSWORD: The database password to pass to Drupal.
MYSQL_USER: The database user to give Drupal.
LANDO_SERVICE_NAME: The name, or address of the database server that the PHP container running Drupal is going to use to contact the database. Usually this could be something like
127.0.01, but because the database is not running “locally” inside the PHP container, it needs another address.
Lando uses Docker Compose in the background to orchestrate Docker services. In fact, Lando is a big Docker Compose wrapper. When using Docker Compose, services usually have a name. This name is then associated with each services’ container, and accessible to other containers in the Docker network, assuming that service exposes any ports to other containers.
In this case, the database service name is
database. Meaning the PHP container running Drupal will be able to talk to MySQL/MariaDB on the
The values for the database installer are:
- Database name:
- Database username:
- Database password:
- Database host:
I leave the port to the default number
Here are the parameters populated on the Drupal installer page:
Those parameters are successful, and I can see that Drupal is installed into the database:
After the installer completes, I am logged into my brand new Drupal 8.x site, running inside Docker for Windows, with containers provided by Lando, and launched from WSL 2 Ubuntu:
I never intended this story to be an in-depth, exhaustive dive into Lando and it’s plethora of configuration options or recipes. So I glossed over some details that perhaps I can cover in a later post or even better, you can answer in the comments below!
- What happens when you destroy your Lando stack? Do you lose the database?
- Is there a Lando recipe that works better for Drupal 9? Such as having a newer PHP version installed in the Lando container?
- How do you use XDebug with this Lando configuration?
- And lest I forget, where is my Alpine setup 😠 !??!
Here are some hints:
- For the database I don’t see anything on the barebones Lando recipe I used that says to mount a local WSL directory as a mount path into the database
/var/lib/mysqldirectory. That probably means your precious database (and all your billable hours) are gone when you destroy the database container. Have fun!
- The Lando documentation has recipes for all kinds of PHP frameworks and hosting providers. Here is a recipe for Drupal 9.
- As for XDebug, I’ll give you a head start with this document. Note that’s for PHPStorm, good luck with Visual Studio Code and WSL2!
- And finally, I’m still investigating how to get a similar setup working on Alpine WSL. Like I said at the beginning of this story I ran into some initial issues there and it’s something I’m hoping to triage sooner than later!
Also I’m aware that there’s better ways to use the facilities provided by Lando such as Composer automation functions that install Drupal for you — but I wanted to see how far I could get away with as little as possible. Sometimes for me the less magic I use allows me to understand the base system better. But that’s just me.
From Callback Insanity, Happy Dockerizing, and here’s to a better 2021 for everyone!