PHPers Summit 2021

Docksal 101

Bartłomiej Jakub Kwiatek

@Flower7C3

O mnie

Bartłomiej Jakub Kwiatek

@Flower7C3

PHPers Summit 2021
Docksal 101

  • Web developer w PHP z 18-letnim doświadczeniem

  • W codziennej pracy używam HTML, CSS, JS, Bash i Symfony

  • Od 2015 w VMLY&R

  • Więcej na moje stronie kwiatek.pro

Plan spotkania

PHPers Summit 2021
Docksal 101

  1. Co, dlaczego i jak
  2. Dostosowywanie i rozszerzanie
  3. Rozwiązywanie problemów
  4. Przykłady

Plan spotkania

PHPers Summit 2021
Docksal 101

Pytania?

PHPers Summit 2021
Docksal 101

 Gotowi?

PHPers Summit 2021
Docksal 101

PHPers Summit 2021
Docksal 101

Ok, ale...?

Czym jest 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

+

=

Czym jest 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

Dlaczego Docksal?

  • używa kontenery Dockera
  • projekty bez konfiguracji
  • rozszerzalność konfiguracji
  • pliki konfiguracyjne przechowywane projeckie
  • automatyczna konfiguracja i routing wirtualnych hostów
  • wbudowane narzędzia, takie jak Composer, Drush, Drupal Console i WP-CLI
  • więcej...

PHPers Summit 2021
Docksal 101

PHPers Summit 2021
Docksal 101

vs

Vagrant is a tool focused on providing a consistent development environment workflow across multiple operating systems.

Docker is a container management that can consistently run software as long as a containerization system exists.

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

What is Docker?

PHPers Summit 2021
Docksal 101

TL;DR

Pobierz Docksala
docksal.io/installation

PHPers Summit 2021
Docksal 101

„fininitialize”

Otwórz przglądarkę
example.docksal

$ fin init

Jak to działa?

PHPers Summit 2021
Docksal 101

Serwisy systemowe

Serwisy projektowe

  • 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                         

Jak to działa

PHPers Summit 2021
Docksal 101

Polecenie fin

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

Polecenie fin

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
$ 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

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

Dostosowywanie i rozszerzanie

PHPers Summit 2021
Docksal 101

Kontener CLI (PHP i inne)

PHPers Summit 2021
Docksal 101

Image Notes
docksal/cli:php8.0-3.0 PHP 8.0, Nodejs 14.17.3, Ruby 2.5.5, Python 2.7.16, msmtp
docksal/cli:php7.4-3.0 Default image PHP 7.4, Nodejs 14.17.3, Ruby 2.7.2, Python 2.7.16, msmtp
docksal/cli:php7.3-3.0 PHP 7.3, Nodejs 14.17.3, Ruby 2.5.5, Python 3.8.3, msmtp
docksal/cli:php8.0-3 Latest 3.x image version of PHP 8.0 flavor, convenient when extending images
docksal/cli:php7.4-3 Latest 3.x image version of PHP 7.4 flavor, convenient when extending images
docksal/cli:php7.3-3 Latest 3.x image version of PHP 7.3 flavor, convenient when extending images
docksal/cli:2.13-php7.4 PHP 7.4, Nodejs 14.15.0, Ruby 2.7.2, Python 3.8.3, msmtp
docksal/cli:2.13-php7.3 PHP 7.3, Nodejs 14.15.0, Ruby 2.7.2, Python 3.8.3, msmtp
docksal/cli:2.11-php7.2 Deprecated PHP 7.2, Nodejs 12.18.1, Ruby 2.7.1, Python 3.8.3, msmtp
docksal/cli:2.10-php7.1 Deprecated PHP 7.1, Nodejs 12.13.0, Ruby 2.6.5, Python 3.8.3, msmtp
docksal/cli:2.5-php7.0 Deprecated PHP 7.0, mhsendmail
docksal/cli:2.5-php5.6 Deprecated PHP 5.6, mhsendmail
fin exec echo 10.12.0 > .nvmrc
fin exec nvm install

Kontener bazy danych

PHPers Summit 2021
Docksal 101

$ fin image registry docksal/db                              
docksal/db:latest
docksal/db:1.0-mysql-5.5
docksal/db:1.0-mysql-5.6
docksal/db:1.0-mysql-5.7
docksal/db:1.0-mysql-8.0
docksal/db:1.1-mysql-5.5
docksal/db:1.1-mysql-5.6
docksal/db:1.1-mysql-5.7
docksal/db:1.1-mysql-8.0
docksal/db:1.2-mysql-5.5
docksal/db:1.2-mysql-5.6
docksal/db:1.2-mysql-5.7
docksal/db:1.2-mysql-8.0
docksal/db:1.3-mysql-5.5
docksal/db:1.3-mysql-5.6
docksal/db:1.3-mysql-5.7
docksal/db:1.3-mysql-8.0
docksal/db:edge-mysql-5.5
docksal/db:edge-mysql-5.6
docksal/db:edge-mysql-5.7
docksal/db:edge-mysql-8.0
docksal/db:mysql-5.5
docksal/db:mysql-5.6
docksal/db:mysql-5.7
docksal/db:mysql-8.0
$ 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> 

Kontener bazy danych

PHPers Summit 2021
Docksal 101

$ 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                                                                                                                                                                  

Udostępnij światu

PHPers Summit 2021
Docksal 101

Chcesz więcej?

PHPers Summit 2021
Docksal 101

Zerknij do dokumentacji » docs.docksal.io

Rozwiązywanie problemów

PHPers Summit 2021
Docksal 101

  • porównaj konfigurację z kolegami

  • zaktualizuj Dockera, ale...

  • zaktualizuj Docksala

  • przennieś projetkt poza katalog pulpitu

  • zmień typ montowania woluminów — docs.docksal.io/core/volumes/
     

  • zabij projes siedzący na portcie 80

  • zabij firewalla, antywirusa

  • zrestartuj komputer

  • other » docs.docksal.io/troubleshooting

 

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

Rozwiązywanie problemów

PHPers Summit 2021
Docksal 101

Czas na przedstawienie

PHPers Summit 2021
Docksal 101

  • Jak to wygląda w projekcie
  • Rozszerzenie konfiguracjia
  • Konfiguracja za pomocą buildera

Zacznijmy to

PHPers Summit 2021
Docksal 101

Pytania?

PHPers Summit 2021
Docksal 101

PHPers Summit 2021
Docksal 101

Pamiętajcie o dokumentacji » docs.docksal.io

Bartłomiej Jakub Kwiatek

@Flower7C3

Kwiatek.pro

Bartlomiej.Kwiatek@VMLYR.com

PHPers Summit 2021
Docksal 101

Made with Slides.com