Docksal 101

Bartłomiej Jakub Kwiatek

@Flower7C3

PHPers Summit 2021

workshop

  • Web developer in PHP with 18 years of experience

  • In daily programming use also HTML, CSS, JS, Bash and Symfony

  • Since 2015 VMLY&R

  • Live in Niepołomice near Kraków

  • Like cycling and trips with my family

  • View more on personal home page kwiatek.pro

PHPers Summit 2021
Docksal 101

About me

Bartłomiej Jakub Kwiatek

@Flower7C3

Meeting plan

PHPers Summit 2021
Docksal 101

  • Whats Your knowledge and experience?
  • What do you expect from this training?

Meeting plan

PHPers Summit 2021
Docksal 101

Theory part

  1. Apps development
  2. Vagrant vs Docker
  3. Why Docksal?
  4. How it works?

Meeting plan

Practical part

  1. Prepare
  2. Customization & extending
  3. Troubleshooting
  4. Ok, lets init this

PHPers Summit 2021
Docksal 101

PHPers Summit 2021
Docksal 101

Any questions?

Apps development

PHPers Summit 2021
Docksal 101

  • Standard is Apache + PHP + MySQL

  • Simple with LAMP, XAMP, WAMP...

  • But which version?

Local

  • VPS
  • cloud
  • AWS

  • other?

Remote

Apps development

PHPers Summit 2021
Docksal 101

  • What if I have multiple projects?

  • It uses a lot of CPU and RAM…

  • How to easily introduce a new employee into the project?

  • Is it possible to have multiple PHP versions
    or quickly install Mongo, Redis or something else?

Apps development

Blockers?

PHPers Summit 2021
Docksal 101

PHPers Summit 2021
Docksal 101

vs

tool for building and managing virtual machine environments

in a single workflow

 

» vagrantup.com/intro

is specifically designed for software development purposes

 

» dzone.com/articles/vagrant-vs-docker-which-is-better-for-software-dev

PHPers Summit 2021
Docksal 101

only independent container platform
that enables organizations to seamlessly build, share

and run any application, anywhere - from hybrid cloud to the edge

 

» docker.com/what-docker

production-ready environment that provides consistent app usage experience

throughout the whole software delivery pipeline

 

» dzone.com/articles/vagrant-vs-docker-which-is-better-for-software-dev

PHPers Summit 2021
Docksal 101

PHPers Summit 2021
Docksal 101

vs

But why?

PHPers Summit 2021
Docksal 101

What is Docksal?

PHPers Summit 2021
Docksal 101

Docker + Dorsal = Docksal
The Dorsal is a fin!
The fin on top/back of a fish or whale is its dorsal fin.

 

» github.com/docksal/docksal/discussions/1554

+

=

What is Docksal?

PHPers Summit 2021
Docksal 101

Docksal is a tool for defining and managing
web development environments.
It uses Docker and Docker Compose
to create fully containerized environments for your projects.

 

» docs.docksal.io

Why Docksal?

PHPers Summit 2021
Docksal 101

Why Docksal?

  • uses Docker containers
  • zero-configuration projects
  • easy to create configurations to partially or fully override any defaults
  • config files stored in same GIT repository as project
  • automatic virtual host configuration and routing (contains DNS resolver)
  • built-in tools such as Composer, Drush, Drupal Console, and WP-CLI
  • more...

PHPers Summit 2021
Docksal 101

Can I use Docksal?

PHPers Summit 2021
Docksal 101

  • RAM requirement: 8GB or more
  • Mac - must be a 2010 or newer model
  • Linux, CPU with SSE4.2 instruction set supported
  • Windows 10 and CPU
    with hardware virtualization (VT-x/AMD-V) supported
    and enabled in BIOS

 

Details » docs.docksal.io/getting-started/setup/

How to Docksal?

Download Docksal
docksal.io/installation

PHPers Summit 2021
Docksal 101

„fininitialize”

Open browser
example.docksal

$ fin init

How it works?

PHPers Summit 2021
Docksal 101

System Services

Project Services

  • SSH Agent
  • DNS
  • Reverse Proxy
  • cli
  • db
  • web
  • other?
$ fin system status
CONTAINER ID   IMAGE                     COMMAND                  CREATED        STATUS                 PORTS                                      NAMES
681c468cb636   docksal/ssh-agent:1.3     "docker-entrypoint.s…"   30 hours ago   Up 9 hours (healthy)                                              docksal-ssh-agent
68d4b3ad26c5   docksal/dns:1.1           "docker-entrypoint.s…"   30 hours ago   Up 9 hours (healthy)   0.0.0.0:53->53/udp                         docksal-dns
b174672323cf   docksal/vhost-proxy:1.7   "docker-entrypoint.s…"   30 hours ago   Up 9 hours (healthy)   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   docksal-vhost-proxy
$ fin ps
    Name                      Command              State                      Ports                  
-----------------------------------------------------------------------------------------------------
example_com_cli_1   /opt/startup.sh supervisord   Exit 255   22/tcp, 3000/tcp, 9000/tcp              
example_com_db_1    docker-entrypoint.sh mysqld   Exit 255   0.0.0.0:3064->3306/tcp,:::3064->3306/tcp
example_com_web_1   httpd-foreground              Exit 255   443/tcp, 80/tcp                         

How it works?

PHPers Summit 2021
Docksal 101

How it works?

PHPers Summit 2021
Docksal 101

How it works?

PHPers Summit 2021
Docksal 101

$ fin
Docksal command line utility (v1.106.0)
Docksal docs: https://docs.docksal.io/

Usage: fin [command]

Management Commands:
  db <command>             	Manage databases (fin help db)
  project <command>        	Manage project(s) (fin help project)
  ssh-key <command>        	Manage SSH keys (fin help ssh-key)
  system <command>         	Manage Docksal state (fin help system)

Commands:
  bash [service]           	Open shell into services container. Defaults to cli
  logs [service]           	Show service logs (e.g., Apache logs, MySQL logs) and Unison logs (fin help logs)
  exec <command|file>      	Execute a command or a script in cli
  config [command]         	Show or change configuration (fin help config)
  run-cli (rc) <command>   	Run a command in a standalone cli container in the current directory (fin help run-cli)

  pull [options]           	Commands for interacting with Hosting Provider (fin help pull)
  drush [command]          	Drush command (requires Drupal)
  drupal [command]         	Drupal Console command (requires Drupal 8)
  platform [command]       	Platform.sh's CLI (requires docksal/cli 2.3+)
  terminus [command]       	Pantheon's Terminus (requires docksal/cli 2.1+)
  wp [command]             	WordPress CLI command (requires WordPress)
  composer [command]       	Run Composer commands
  docker (d) [command]     	Run Docker commands directly
  docker-compose (dc) [cmd]	Run Docker Compose commands directly

  init                     	Initialize a project (override it with your own automation, see fin help init)
  addon <command>          	Addons management commands: install, remove (fin help addon)
  alias                    	Manage aliases that allow fin @alias execution (fin help alias)
  cleanup [options]        	Remove all unused Docker images, unused Docksal volumes and containers
  share                    	Create temporary public url for current project using ngrok
  exec-url <url>           	Download script from URL and run it on host (URL should be public)
  image <command>          	Image management commands: registry, save, load (fin help image)
  hosts <command>          	Hosts file commands: add, remove, list (fin help hosts)
  vhosts                   	List all virtual *.docksal hosts registered in Docksal proxy
  sysinfo                  	Show system information
  diagnose                 	Show diagnostic information for troubleshooting and bug reporting
  version (--version, v, -v)	Print fin version. [v, -v] prints short version
  update                   	Update Docksal

Addons found:
  mkcert [g]               	mkcert addon

Custom commands found:
  init                     	No description
  gulp [g]                 	Run gulp
  init-gulp [g]            	Install valid NPM via NVM, install all NVM resources, install gulp and gulp-cli.
  npm [g]                  	Run npm
  open [g]                 	Open VIRTUAL_HOST in browser.
  warmup [g]               	Warmup Docksal configuration for project
$ fin init
Initialize a project in /Users/bartlomiej.kwiatek/Projects/testy/example_com? [y/n]: y
DOCROOT has been detected as docroot. Is that correct? [y/n]: y
Configuration was generated. You can start it with fin project start
Removing containers...
Removing network example_com_default
WARNING: Network example_com_default not found.
Removing volume example_com_cli_home
WARNING: Volume example_com_cli_home not found.
Removing volume example_com_project_root
WARNING: Volume example_com_project_root not found.
Removing volume example_com_db_data
WARNING: Volume example_com_db_data not found.
Volume docksal_ssh_agent is external, skipping
Starting services...
Creating network "example_com_default" with the default driver
Creating volume "example_com_cli_home" with default driver
Creating volume "example_com_project_root" with local driver
Creating volume "example_com_db_data" with default driver
Creating example_com_cli_1 ... done
Creating example_com_db_1  ... done
Creating example_com_web_1 ... done
Connected vhost-proxy to "example_com_default" network.
Waiting for project stack to become ready...
Project URL: http://example-com.docksal
$ fin config
---------------------
COMPOSE_PROJECT_NAME_SAFE: example_com
COMPOSE_FILE:
/Users/bartlomiej.kwiatek/.docksal/stacks/volumes-nfs.yml
/Users/bartlomiej.kwiatek/.docksal/stacks/stack-default.yml
/Users/bartlomiej.kwiatek/Projects/testy/example_com/.docksal/docksal.yml
ENV_FILE:
/Users/bartlomiej.kwiatek/Projects/testy/example_com/.docksal/docksal.env

PROJECT_ROOT: /Users/bartlomiej.kwiatek/Projects/testy/example_com
DOCROOT: docroot
VIRTUAL_HOST: example-com.docksal
VIRTUAL_HOST_ALIASES: *.example-com.docksal
IP: 192.168.64.100
MYSQL: 192.168.64.100:64493

Docker Compose configuration
---------------------
services:
  cli:
    dns:
    - 192.168.64.100
    - 8.8.8.8
    environment:
      BLACKFIRE_CLIENT_ID: null
      BLACKFIRE_CLIENT_TOKEN: null
      COMPOSER_ALLOW_XDEBUG: '0'
      COMPOSER_DEFAULT_VERSION: null
      COMPOSER_DISABLE_XDEBUG_WARN: '0'
      DOCROOT: docroot
      DRUSH_ALLOW_XDEBUG: '0'
      DRUSH_OPTIONS_URI: example-com.docksal
      GIT_USER_EMAIL: bartlomiej.kwiatek@vmlyr.com
      GIT_USER_NAME: Bartlomiej.Kwiatek
      HOST_GID: '824956060'
      HOST_UID: '1447064522'
      MYSQL_DATABASE: default
      MYSQL_HOST: db
      MYSQL_PASSWORD: user
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: user
      PHP_IDE_CONFIG: null
      SECRET_ACAPI_EMAIL: null
      SECRET_ACAPI_KEY: null
      SECRET_ACQUIACLI_KEY: null
      SECRET_ACQUIACLI_SECRET: null
      SECRET_PLATFORMSH_CLI_TOKEN: null
      SECRET_SSH_PRIVATE_KEY: null
      SECRET_TERMINUS_TOKEN: null
      SSH_AUTH_SOCK: /.ssh-agent/proxy-socket
      VIRTUAL_HOST: example-com.docksal
      XDEBUG_CONFIG: client_host=192.168.64.1 remote_host=192.168.64.1
      XDEBUG_ENABLED: '0'
    healthcheck:
      interval: 10s
    hostname: cli
    image: docksal/cli:php7.4-3.0
    labels:
      io.docksal.shell: bash
      io.docksal.user: docker
    logging:
      options:
        max-file: '10'
        max-size: 1m
    volumes:
    - docksal_ssh_agent:/.ssh-agent:ro
    - cli_home:/home/docker:rw
    - /tmp/.docksal/example_com:/tmp/.docksal/example_com:ro
    - project_root:/var/www:rw,nocopy,cached
  db:
    dns:
    - 192.168.64.100
    - 8.8.8.8
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: null
      MYSQL_DATABASE: default
      MYSQL_INITDB_SKIP_TZINFO: null
      MYSQL_ONETIME_PASSWORD: null
      MYSQL_PASSWORD: user
      MYSQL_RANDOM_ROOT_PASSWORD: null
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: user
    healthcheck:
      interval: 10s
    hostname: db
    image: docksal/mysql:5.7-1.5
    logging:
      options:
        max-file: '10'
        max-size: 1m
    ports:
    - target: 3306
    volumes:
    - db_data:/var/lib/mysql:rw
    - project_root:/var/www:ro,nocopy,cached
  web:
    depends_on:
      cli:
        condition: service_started
    dns:
    - 192.168.64.100
    - 8.8.8.8
    environment:
      APACHE_BASIC_AUTH_PASS: null
      APACHE_BASIC_AUTH_USER: null
      APACHE_DOCUMENTROOT: /var/www/docroot
      APACHE_FCGI_HOST_PORT: cli:9000
    healthcheck:
      interval: 10s
    hostname: web
    image: docksal/apache:2.4-2.3
    labels:
      io.docksal.cert-name: none
      io.docksal.permanent: "false"
      io.docksal.project-root: /Users/bartlomiej.kwiatek/Projects/testy/example_com
      io.docksal.virtual-host: example-com.docksal,*.example-com.docksal,example-com.docksal.*
    logging:
      options:
        max-file: '10'
        max-size: 1m
    volumes:
    - project_root:/var/www:ro,nocopy,cached
version: '3.9'
volumes:
  cli_home: {}
  db_data: {}
  docksal_ssh_agent:
    external: true
    name: docksal_ssh_agent
  project_root:
    driver: local
    driver_opts:
      device: :/Users/bartlomiej.kwiatek/Projects/testy/example_com
      o: addr=192.168.64.1,vers=3,nolock,noacl,nocto,noatime,nodiratime,actimeo=1
      type: nfs

---------------------

How it works?

PHPers Summit 2021
Docksal 101

docker-compose up -d
docker exec –ti 139b97d58fad bash
docker exec -ti 9efee5a2d431 mysql
docker exec -ti 139b97d58fad php $(which composer)
???
fin start
fin bash
fin db cli
fin composer
fin vhosts

Prepare

PHPers Summit 2021
Docksal 101

Prepare

PHPers Summit 2021
Docksal 101

Prepare

PHPers Summit 2021
Docksal 101

Customization & extending

PHPers Summit 2021
Docksal 101

  • PHP versions and configuration
  • databases
  • Node.js versions
  • HTTPS
  • external access
  • other?

read more » docs.docksal.io/tools

Customization & extending

PHPers Summit 2021
Docksal 101

Custom commands

PHPers Summit 2021
Docksal 101

PHP versions and configuration

PHPers Summit 2021
Docksal 101

Databases

PHPers Summit 2021
Docksal 101

$ fin db cli
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 68
Server version: 5.7.30 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

Node.js versions

PHPers Summit 2021
Docksal 101

$ fin mkcert create
Using the local CA at "/Users/bartlomiej.kwiatek/Library/Application Support/mkcert" ✨
Warning: the local CA is not installed in the Firefox trust store! ⚠️
Run "mkcert -install" to avoid verification errors ‼️

Created a new certificate valid for the following names 📜
 - "*.example-com.docksal"
 - "example-com.docksal"

Reminder: X.509 wildcards only go one level deep, so this won't match a.b.example-com.docksal ℹ️

The certificate is at "/Users/bartlomiej.kwiatek/.docksal/certs/example-com.docksal.crt" and the key at "/Users/bartlomiej.kwiatek/.docksal/certs/example-com.docksal.key" ✅

Run fin project restart to load the new cert.
$ fin share
Exposing domain example-com.docksal via ngrok...

ngrok by @inconshreveable                                                                                                                                                                                                   (Ctrl+C to quit)
                                                                                                                                                                                                                                            
Session Status                online                                                                                                                                                                                                        
Session Expires               1 hour, 59 minutes                                                                                                                                                                                            
Version                       2.3.40                                                                                                                                                                                                        
Region                        United States (us)                                                                                                                                                                                            
Web Interface                 http://0.0.0.0:4040                                                                                                                                                                                           
Forwarding                    http://4037-46-29-22-102.ngrok.io -> http://example_com_web_1.example_com_default:80                                                                                                                          
Forwarding                    https://4037-46-29-22-102.ngrok.io -> http://example_com_web_1.example_com_default:80                                                                                                                         
                                                                                                                                                                                                                                            
Connections                   ttl     opn     rt1     rt5     p50     p90                                                                                                                                                                   
                              0       0       0.00    0.00    0.00    0.00                                                                                                                                                                  

Other tools

PHPers Summit 2021
Docksal 101

Ok, lets init this

PHPers Summit 2021
Docksal 101

Ok, lets init this

PHPers Summit 2021
Docksal 101

  • Create project from boilerplate
  • Add Docksal to existing project
  • Append with custom configuration
  • Simplify with warmup

Ok, lets init this

PHPers Summit 2021
Docksal 101

Troubleshooting

PHPers Summit 2021
Docksal 101

  • compare configuration with collegues

  • update Docker

  • update Docksal

  • move poroject outside from ~/Destkop/ directory

  • change volumes mount type — docs.docksal.io/core/volumes/

     

  • kill process that uses port 80

  • kill firewall, antivirus program

  • restart computer

  • other » docs.docksal.io/troubleshooting

 

fin config set --global DOCKSAL_VOLUMES=nfs
fin system reset
fin sysinfo
fin update
lsof -i :80

Troubleshooting

PHPers Summit 2021
Docksal 101

Any questions?

PHPers Summit 2021
Docksal 101

PHPers Summit 2021
Docksal 101

Remember to read the docs.docksal.io

PHPers Summit 2021
Docksal 101

Bartłomiej Jakub Kwiatek

@Flower7C3

Kwiatek.pro

Bartlomiej.Kwiatek@VMLYR.com

Made with Slides.com