Liberté, égalité, fraternité:

Local development in Docker containers with

Who are we?

Jeffrey Bertoen

@JeffreyBertoen

drupal.org/u/jefuri

Daniël Smidt

@dmsmidt

drupal.org/u/dmsmidt

What to use as local web development environement?

LAMP/LEMP

Current landscape

  • Local / native
    e.g. xAmp/Acquia Dev Desktop
     
  • Virtual Machine
    VirtualBox/VMware
     
  • Virtual Environments (containers)
    LXC/Docker

Why go virtual?

  • Host OS independent
  • Same environment as colleagues 
  • Same environment (versions) as (production) server
  • Hosting software and application code as a bundle
  • Keep everything in a VCS (git)
  • Easy rollback / reset
  • Sandboxed, less influenced by other software

Why not to go virtual?

  • Can be slower, but depends on:
    • Host OS
    • Type: VM or VE
  • More difficult to run certain tests
  • Needs more system resources

Virtual Machine (VM)

V.S.

Virtual Environment (VE)

VM: Fake complete isolated machine(s) with their own OS

VM: Singe OS centred with multiple applications per instance

VE: Hardware layer and OS Kernel are not virtualised (faster)

VE: Single application / process per container

V.M.

V.S.

V.E.

And the winner is: VE!

Scale: Run WAY more containers per infrastructure

Speed: Start, stop, destroy in seconds vs minutes

Separation of Concerns: One service per container

Why Docker?

  • All benefits of going virtual
  • Based on LXC, but easier to manage
  • Big library of reusable container images
  • Layered Filesystem (reuse images)
  • A lot of helpful toolkits (e.g. Lando)

The Docker Drupal Dev toolkits

 

  • (Docker4Drupal)
  • DDEV
  • Docksal (VM + VE)
  • Lagoon
  • Lando

Disclaimer: We haven’t tried all options!

Different Pros

 

  • Lando and Lagoon have the best hosting integration* 
  • Lagoon and Drupal4Docker don’t offer additional tooling
  • DDEV shares project data with host (db, uploads), not lost after reset**
  • Lando and DDEV will get a GUI
  • Lando has the most pre-made configurations
  • Docksal is fastest on Mac ("Cheats" with VM mode)

 

     *) Pantheon and Amazee.io respectively

     **) Others can also be setup like this

 

  • Easier onboarding of new developers
  • Easier debugging of environment specific problems
  • Less system administrative waste of time (it work’s on my computer)
  • Temporary environments for user tests

In practice Lando solves @wearesynetic

What does Lando offer?

One YML to rule them all!

  • Simple in repo config file: .lando.yml
  • Use basic preconfigured stacks
  • Add in additional services eg solr
  • Add in additional tools eg node
  • Build and automation steps
  • Hosting integrations (Pantheon)
  • Docker compose abstraction layers
  • Cross platform
  • Local dev dependency management

Support

Growing Community

Commits

Version adoption

Open Source:

We contributed!

  • Documentation
  • Apache SOLR
  • Wildcard domains
  • BlackFire integration
  • Bug fixes

Documentation

Recipes

CMS/Frameworks

  • Drupal (6/7/8)
  • Backdrop
  • Wordpress
  • Joomla
  • Laravel

Architecture

  • LAMP
  • LEMP
  • MEAN
  • Go
  • Ruby
  • Python
  • Dotnet

Services

Elasticsearch

Solr

MongoDB

Apache

Nginx

Tomcat

MySQL

MariaDB

Postgres SQL

MS SQL

Redis

Memcached

Varnish

PHP

Node

Go

Ruby

Python

CLI Commands

Commands:
  config                   Display the lando configuration
  destroy [appname]        Destroy app in current directory or [appname]
  info [appname]           Prints info about app in current directory or [appname]
  init [method]            Initialize a lando app, optional methods: github, pantheon
  list                     List all lando apps
  logs [appname]           Get logs for app in current directory or [appname]
  poweroff                 Spin down all lando related containers
  rebuild [appname]        Rebuilds app in current directory or [appname]
  restart [appname]        Restarts app in current directory or [appname]
  share [appname]          Get a publicly available url
  ssh [appname] [service]  SSH into [service] in current app directory or [appname]
  start [appname]          Start app in current directory or [appname]
  stop [appname]           Stops app in current directory or [appname]
  version                  Display the lando version

Customization

Services

CLI Tools

Scripts

Multiproject proxy using Docker networks that rocks

How to install, setup and run a project in Lando?

Install Lando

Go to the docs and follow the instructions:

https://docs.devwithlando.io/installation/installing.html

PS - Your CLI tool will inform you when there are future updates!

You get the latest from:
https://github.com/lando/lando/releases

Configure Lando

Edit or create ~/.lando/config.yml

# Automatically turn lando project names into [PROJECTNAME].localhost.
# By default this is lndo.site which only work when you have an active internet connection.
proxyDomain: localhost

# Make passphrase protected keys available in the containers.
# This will ask you for a password each time the key is used from the container.
loadPassphraseProtectedKeys: true

Setup a project

# Get your code base from some repository or create a new project.
git checkout https://some.project.url/repo.git my_lando_app
cd my_lando_app

# Initialize this for lando, this will create a .lando.yml file.
lando init

# OR if you already know which recipe to use:
lando init --recipe drupal8
name: my-lando-app
recipe: drupal8
config:
  webroot: .

Configure some services

name: my-lando-app
recipe: drupal8
config:
  webroot: .

# These are the url's to use for your project. The key, such as nginx, solr, etc,
# are the services that are defined below.
# https://docs.devwithlando.io/config/proxy.html
proxy:
  appserver:
    - my-lando-app.localhost
    # This works as well, for instance when working with the domain access module.
    - *.my-lando-app.localhost
  solr:
    - solr.my-lando-app.localhost:8983

# We can add additional services here or even override some configuration.
services:
  # https://docs.devwithlando.io/services/solr.html
  solr:
    type: solr:5.5
    portforward: true
    core: core-name
    config:
      conf: location/of/your/conf/solr

Start or Rebuild

# Use start if you have not started lando for your project before. 
# Or when you used lando destroy -y on the project.
lando start

# If not, and you changed something to the .lando.yml file, use rebuild.
lando rebuild

# If you changed database stuff, it might be necessary to do a lando destroy first.
lando destroy
lando start

And then view your project

Available CLI tools

Usage: lando <command> [args] [options] [-- global options]

Commands:
  composer                 Run composer commands
  config                   Display the lando configuration
  db-export [file]         Export a database. Resulting file: {DB_NAME}.TIMESTAMP.gz
  db-import [file]         Import into database.
  destroy [appname]        Destroy app in current directory or [appname]
  drupal                   Run drupal console commands
  drush                    Run drush commands
  info [appname]           Prints info about app in current directory or [appname]
  init [method]            Initialize a lando app, optional methods: github, pantheon
  list                     List all lando apps
  logs [appname]           Get logs for app in current directory or [appname]
  mysql                    Drop into a MySQL shell
  php                      Run php commands
  poweroff                 Spin down all lando related containers
  rebuild [appname]        Rebuilds app in current directory or [appname]
  restart [appname]        Restarts app in current directory or [appname]
  share [appname]          Get a publicly available url
  ssh [appname] [service]  SSH into [service] in current app directory or [appname]
  start [appname]          Start app in current directory or [appname]
  stop [appname]           Stops app in current directory or [appname]
  version                  Display the lando version

Global Options:
  --help, -h  Show help
  --verbose, -v, -vv, -vvv, -vvvv  Change verbosity of output

You need at least one command before moving on

Live Demo!

https://www.youtube.com/watch?v=RUC44wCJheE

# STEP 0
# Make sure we have a drupal project.
# cmd: composer create-project drupal-composer/drupal-project:8.x-dev my_lando_app --stability dev --no-interaction

# STEP 1
# cmd: lando --recipe drupal8
# cmd: lando start
name: my-lando-app
recipe: drupal8
config:
  webroot: web

# STEP 2
# Show compose file
# cmd: cd ~/.lando/compose/my-lando-app
# cmd: cat my-lando-app-X.yml

# STEP 3
# Add some events.
events:
  pre-db-import:
    - appserver: drush cr
  post-db-import:
    - appserver: composer install

# STEP 4
# Import a DB.
# cmd: lando rebuild -y
# cmd: lando db-import dump.sql.gz

# STEP 5
# Add Apache Solr and MailHog as a service.
services:
  solr:
    type: solr:6.6
    portforward: true
    core: my_lando_app
    config:
      conf: config/solr
  mailhog:
    type: mailhog
    hogfrom:
      - appserver
    portforward: true

# STEP 6
# Add dynamic url's.
proxy:
  appserver:
    - my-lando-app.localhost
    - '*.domains.my-lando-app.localhost'
  solr:
    - solr.my-lando-app.localhost:8983
  mailhog:
    - mailhog.my-lando-app.localhost

# STEP 7
# Rebuild Lando
# cmd: lando rebuild -y

# STEP 8
# Show solr.my-lando-app.localhost
# Show Apache Solr status in drupal 8

# STEP 9
# Show mailhog.my-lando-app.localhost
# Show mailhog password reset mail

# STEP 10
# Tooling example with a simple message.
# cmd: lando rebuild -y
# cmd: lando message
tooling:
  message:
    service: appserver
    description: "Shows a message"
    cmd: echo Lando is freaking awesome!

# STEP 11
# Show xDebug

# STEP 12
# cmd: lando share -u localhost:port

In conclusion

Liberté: Be free of your native dev environment

Égalité: Have the same env as your co-workers and servers

Fraternité: Contribute and share in the happiness

No French have been harmed during the creation of this presentation

Questions?

Liberté, égalité, fraternité: Local development in Docker containers met Lando

By jefuri

Liberté, égalité, fraternité: Local development in Docker containers met Lando

  • 730

More from jefuri