A development environment is composed of several services, at least we have a web server and a database, with the emergence of Docker and the wonderful docker-compose.yml
made our life a lot easier, but calm down, you can stay still best.
What is Lando?
A superset for Docker, Lando provides ways for developers to run complex commands, build steps and automation in their services without using Dockerfile
, docker-compose.yml
or lengthy docker exec
commands.
But can’t I just use Docker?
Yes, but you see, it is made to simplify and speed up the creation of development environment, so yes, you can use Docker but Lando will do the same thing with just a single command.
Here’s an example of the same application:
With lando.yml
name: myapp
recipe: drupal9
With docker-compose.yml
version: "3"
services:
mysql:
image: mysql:8.0
container_name: mysql
command: --default-authentication-plugin=mysql_native_password
restart: unless-stopped
env_file: .env
volumes:
- db-data:/var/lib/mysql
networks:
- internal
drupal:
image: drupal:8.7.8-fpm-alpine
container_name: drupal
depends_on:
- mysql
restart: unless-stopped
networks:
- internal
- external
volumes:
- drupal-data:/var/www/html
webserver:
image: nginx:1.17.4-alpine
container_name: webserver
depends_on:
- drupal
restart: unless-stopped
ports:
- 80:80
volumes:
- drupal-data:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
networks:
- external
networks:
external:
driver: bridge
internal:
driver: bridge
volumes:
drupal-data:
db-data:
So if that didn’t convince you to use Lando I don’t know what else to say.
Hands-on
To make it easier to understand, let’s upload a PHP and Mysql server, the famous LAMP, but don’t worry about that, Lando has several recipes making it possible to run multiple services in a simple way.
Installing Lando
Lando has a very complete documentation, first don’t forget to install Docker so to install it Here we will follow the official documentation.
Running a LAMP application
Lamp (Linux, Apache, MySQL, PHP/Perl/Python) is an acronym for the most used web applications together and, for this reason, there are several tools for this, Lando is one more way.
First let’s create a project directory:
mkdir lamp_lando
Open the folder:
cd lamp_lando
Inside the directory, just initialize Lando with:
lando init
Here some questions about the project will be asked, which will be according to the desired stack, for our project we will answer as follows:
From where should we get your apps's codebase? : [current working directory]
What recipe do you want to use?: [lamp]
Where is your webroot relative to the init destination?: [.]
What do you want to call this app? [LAMP Project]
And we start our application:
lando start
Wait a while, the docker containers will be downloaded, this may take a while depending on your computer and your internet, and once it is finished you will have a screen similar to the one below:
___ __ __ __ __ ______
/ _ )___ ___ __ _ ___ / / ___ _/ /_____ _/ /__ _/ /_____ _/ / / /
/ _ / _ \/ _ \/ ' \(_-</ _ \/ _ `/ '_/ _ `/ / _ `/ '_/ _ `/_/_/_/
/____/\___/\___/_/_/_/___/_//_/\_,_/_/\_\\_,_/_/\_,_/_/\_\\_,_(_|_|_)
Your app has started up correctly.
Here are some vitals:
NAME my-lando-app
LOCATION /home/diego/Projects/lamp_lando
SERVICES appserver, database
APPSERVER URLS https://localhost:49185
http://localhost:49186
http://my-lando-app.lndo.site/
https://my-lando-app.lndo.site/
With everything configured for this, let’s create an info.php
file with the following content:
<?php
phpinfo();
And by accessing the /info.php
we can see our server running.
Listing Lando data
Another very useful command is lando info
it lists all server settings, such as web server address, database and even database passwords, here is an example of the command output:
[ { service: 'appserver',
urls:
[ 'https://localhost:49185',
'http://localhost:49186',
'http://my-lando-app.lndo.site/',
'https://my-lando-app.lndo.site/' ],
type: 'php',
healthy: true,
via: 'apache',
webroot: '.',
config: {},
version: '7.4',
meUser: 'www-data',
hasCerts: true,
hostnames: [ 'appserver.mylandoapp.internal' ] },
{ service: 'database',
urls: [],
type: 'mysql',
healthy: true,
internal_connection: { host: 'database', port: '3306' },
external_connection: { host: '127.0.0.1', port: '49182' },
healthcheck: 'bash -c "[ -f /bitnami/mysql/.mysql_initialized ]"',
creds: { database: 'lamp', password: 'lamp', user: 'lamp' },
config: {},
version: '5.7',
meUser: 'www-data',
hasCerts: false,
hostnames: [ 'database.mylandoapp.internal' ] } ]
And like magic we have a development environment set up.
Development environment, don’t forget
In the official documentation it is clearly stated that Lando is a tool to create and facilitate development environments, so under no circumstances use it in a production environment.
Some commands
First of all I will leave here a list of essential commands, some used above and others not, but that can help a lot.
lando config
Displays Lando’s configuration.
lando destroy
Destroys the application, completely erasing the created Docker containers and volumes.
lando info
Displays application configuration, such as web server and database addresses, as well as database passwords.
lando init
Initializes a project with Lando.
lando list
Lists all services running with Lando.
lando poweroff
Shut down all application containers.
lando rebuild
Re-creates the application from scratch but retains the data.
lando restart
restart the application.
lando start
Start the application.
lando stop
Stop the application.
lando ssh
Access the application shell.