Mastering the Lando Command for Local Development (with examples)
Lando is an intuitive local development environment and DevOps tool designed to simplify and streamline the process of managing web-based applications. Built on top of Docker, Lando is capable of spinning up environments tailored to a specific development stack, allowing developers to work efficiently with a wide range of frameworks and languages. It provides essential functions to manage the lifecycle of a development project, from initialization to deployment, all within a containerized context. With Lando, developers gain a powerful, cross-platform tool that can significantly enhance productivity and workflow consistency.
Use case 1: Initialize code for use with lando
Code:
lando init
Motivation:
The lando init
command is often the first step in using Lando for a new or existing project. By initializing the code, you set up the necessary configuration required for Docker containers to replicate the environment you desire. This is a crucial process as it simplifies collaboration among team members by ensuring everyone is working in an identical environment, minimizing the infamous “it works on my machine” issue.
Explanation:
The command lando init
tells Lando that you want to initialize a new project configuration. When executed, it guides you through a series of prompts to define or detect settings such as the project directory, the type of project stack you require (e.g., Drupal, Laravel, etc.), and preferences for certain dependencies or services.
Example output:
Upon running lando init
, you may be prompted to input specific configurations. Here’s what a typical output might look like:
$ lando init
? What recipe do you want to use?
- Drupal 7
- Drupal 8
- Laravel
- Custom
? Where is your app code located?
- ./
Initialization complete. Run 'lando start' to kick off your project!
Use case 2: Print information about your app
Code:
lando info
Motivation:
The lando info
command is immensely useful for those developers who need a quick overview of their current application environment. Understanding the specific configurations, port mappings, service URLs, and other critical metadata helps troubleshoot, optimize, and manage applications more effectively. This becomes especially important in complex environments with multiple services interacting with each other.
Explanation:
The command does not require any additional arguments. By executing lando info
, you are invoking Lando to return details about the current configuration and status of your application. This output can then be used to check that your setup is functioning as expected or to share with teammates who need to interact with the environment.
Example output:
After running lando info
, you might see something like this:
$ lando info
NAME myapp
HOSTNAME myapp.lndo.site
SERVICES
- appserver:
Host: localhost
Localhost: 60214
Type: php
Version: 7.4
- database:
Host: localhost
Localhost: 60213
Type: mysql
Version: 5.7
Use case 3: Start your app
Code:
lando start
Motivation:
Starting your application with lando start
is synonymous with launching all your containers and services defined in your Lando configuration. This step is critical as it results in the provisioning and booting up of the necessary environment to work on your project. Performing this operation effectively means you can consistently develop and test in a reliable setting.
Explanation:
This command does not require any extra arguments. When you execute lando start
, it will read the configuration from .lando.yml
file, set up the Docker containers as defined, and start all necessary services (e.g., web server, database) for your application.
Example output: Running the command could yield an output similar to:
$ lando start
Starting app: myapp
Pulling services...
Creating service appserver...
Creating service database...
App started!
Visit http://myapp.lndo.site to view your site.
Use case 4: Stop your app
Code:
lando stop
Motivation: Stopping your application when it’s not in use is a practical way to reduce resource utilization on your machine. By stopping the Lando environment, you free up CPU and memory resources, prolong the lifespan of your machine, and ensure you do not inadvertently maintain long-lived processes that could lead to errors or conflicts later on.
Explanation: No additional arguments are needed for this command. The process of stopping involves temporarily halting the running containers associated with your application without deleting any existing data, making it possible to quickly restart later when needed.
Example output:
A typical result from running lando stop
might be:
$ lando stop
Stopping app: myapp
Shutting down services...
App stopped successfully.
Use case 5: Restart your app
Code:
lando restart
Motivation:
Sometimes changes to the code or configuration require a complete restart of the entire application environment to take effect. Using lando restart
is an efficient way to refresh your app’s state without manually stopping and starting each service. This is particularly useful during development phases involving iterative testing of changes.
Explanation:
The lando restart
command restarts all services defined in your Lando configuration. Essentially, it incorporates both the lando stop
and lando start
processes into one command, reducing user workload and minimizing the potential for errors during manual restarts.
Example output: Example output for this command may look like the following:
$ lando restart
Restarting app: myapp
Stopping all running services...
Starting all services again...
App restarted successfully!
Use case 6: Rebuild your app from scratch, preserving data
Code:
lando rebuild
Motivation:
Rebuilding your application is often necessary after making significant changes to your configuration, such as adding new services or updating existing service versions. Using lando rebuild
allows you to reset your application environment while keeping your data intact, a crucial feature when ensuring configuration changes don’t result in data loss.
Explanation:
Executing the lando rebuild
command initiates a re-creation of your application environment by stopping current services, removing containers, and creating them anew according to the latest configuration specifications. Unlike lando destroy
, this command ensures that any data within volumes is preserved.
Example output:
When you run lando rebuild
, you can expect output such as:
$ lando rebuild
Rebuilding app: myapp
Stopping services...
Recreating containers...
App has been rebuilt successfully.
Data has been preserved.
Use case 7: Display logs for your app
Code:
lando logs
Motivation:
The lando logs
command is invaluable for debugging. By accessing logs, you gain insight into what might have gone wrong with your application, from errors during start-up processes to service-specific issues. This empowers you to diagnose problems efficiently and take informed actions to resolve them.
Explanation: This straightforward command outputs logs from all the services managed by Lando in your application. No additional arguments are required. It provides real-time access to application logs, an essential tool for troubleshooting.
Example output:
Executing lando logs
might reveal information like:
$ lando logs
Appserver logs...
[INFO] Apache is running
[ERROR] Cannot connect to database
Database logs...
[INFO] Database service started successfully
Use case 8: Destroy your app
Code:
lando destroy
Motivation:
The lando destroy
command is essential when you need to completely remove your application’s environment and all its data. It’s useful when starting a new project configuration, purging outdated environments, or running tests that require a fresh setup. Destroying an application ensures that any previous state or data does not interfere with future operations.
Explanation: This command will stop all running services, remove containers, networks, and volumes related to your application. It requires confirmation due to its destructive nature and should be used with caution as it will delete all stored data associated with the project.
Example output:
Upon executing lando destroy
, the command line might output:
$ lando destroy
Are you sure you want to destroy this app? [y/N] y
Destroying app: myapp
Removing containers...
Removing networks...
Cleaning up...
App destroyed successfully.
Conclusion:
The power and flexibility of the Lando CLI tools allow developers to manage complex local development environments with remarkable ease. Whether you are initializing a new project, viewing critical app information, starting or stopping services, reviewing logs, or completely rebuilding your environment, Lando provides a seamless way to streamline your workflow. By mastering Lando, you can significantly enhance your efficiency and ensure that all project requirements are consistently met across different development setups.