Devbox with docker

Jeroen Boersma

Devbox with docker

Jeroen Boersma

Devbox why?

  • PHP 5.6, 7.0, 7.1
  • Dependency hell
  • Magento / Symfony / Silex / Sideprojects
  • Catch outgoing mail
  • Working on multiple projects on daily base
  • Learn docker

Devbox why?

Devbox when?

  • I bought a new laptop...
  • Needed to install that ... . . .. .
  • Started a company
  • Needed to migrate legacy code
  • Didn't want to end up with vagrant
  • First commit just before my youngest child was born, maybe I was preparing
    So, just before 4 July 2015 ;-)

Devbox when?

And again ... Learn docker

Devbox struggles?

  • Did I mention I didn't know docker
  • Docker API changed on daily base
  • Dependency hell
    so.. how the does docker solve this?!?
  • Heavy containers at first(no best practices)
  • Use current local user
  • Logging needed to be omitted to stdout

Devbox struggles?

  • Did everything with docker commands at first
  • Made a clear choice to not run for production
  • Open Sourcing a project raise issues
    • Cool that people addapt
    • They ask questions
  • MacOS ~#$%~ Still a bitch...

Devbox how?

Docker / docker-compose

compose for automating, easy to use .yml files

version: '2'
networks: {}
volumes:
  dockerdev-mysql-volume:
    external: true

services:
  db:
    image: percona
    volumes:
    - ./conf.d/mysql:/etc/mysql/conf.d:ro
    - dockerdev-mysql-volume:/var/lib/mysql:rw
    env_file:
      - ./conf/mysql
    network_mode: bridge
    ports:
      - 127.0.0.1:3306:3306

  mailcatch:
    image: mailhog/mailhog
    network_mode: bridge

  php:
    build:
      context: php7
    links:

Devbox how?

./bin/dev [COMMAND]

 

  • loads correct extra .yml files
  • translates all docker-compose

docker-compose-blackfireclient.yml, docker-compose-linux.yml, docker-custom.yml, docker-compose-blackfire.yml,
docker-compose-mytop.yml, docker-sync.yml,
docker-compose-ctop.yml, docker-compose-osx.yml,
docker-compose-dbclient.yml, docker-compose.yml

Devbox current?

  • Nginx (alpine)
  • php-fpm (custom(debian))
    • php5.6
    • php7.0
    • php7.1
  • redis (alpine)
  • mailhog (alpine)
  • percona (debian)

 

  • blackfire (alpine)
  • mailhog (alpine)
  • mytop (alpine)
  • c(ontainer)top (glibc)

 

 

Only automated builds with Dockerfile

Devbox start?

Install docker (apt/whatever) / docker-compose min 1.6.1

git clone git@github.com:JeroenBoersma/docker-compose-development.git development

vi conf/mysql
# Set MYSQL_ROOT_PASSWORD=ANYTHINGNOTTOSIMPLE

./bin/dev up

# Will download all images
# Will set some local settings for local users
# Will try to start all containers

# MAKE SURE NO LOCAL MySQL/Webserver is running anymore

Devbox database?

Was the biggest speed problem for MacOS
Sync files from local ./mysql -> /var/lib/mysql

 

Solved via a persistent data container

docker volume create dockerdev-mysql-volume

Devbox workspace?

The ./workspace directory is mapped to /data internally

 

./workspace/test/project -> /data/test/project

(htdocs|public|httpdocs|pub) are your public

 

http(s)://test.project.dev/

/data/test/project/public/index.php
./workspace/test/project/public/index.php

 

Devbox access?

*.dev -> 127.0.0.1 (via hosts or local dns)

still on my todo: making this configurable

Default PHP 7.0

Devbox access?

  • *.php5.dev -> PHP 5.6
  • *.php71.dev -> PHP 7.1

 

  • *.magento.dev
  • *.magento2.dev (/pub)
  • *.symfony.dev (/web)
  • *.silex.dev (/web)

 

Devbox hosts?

  • db -> MySQL
  • redis -> redis

Devbox demo!

$ dev up

Creating development_db_1
Creating development_blackfire_1
Creating development_mailcatch_1
Creating development_redis_1
Creating development_php_1
Creating development_php71_1
Creating development_php5_1
Creating development_web_1

Devbox commands?

Via ./bin/dev [COMMAND]

 

Run ./bin/dev profile and add to your profile

$ ./bin/dev profile

export PATH=/home/jeroen/docker/development/bin:${PATH};
alias cdw='cd /home/jeroen/docker/development/workspace';

Devbox tools?

  • Separate process
  • PHP tools inside PHP container

 

  • composer
  • magerun
  • magerun2
  • console

Devbox tools?

  • mysql
  • mysqldump
  • mytop
  • top
  • blackfire
  • logs

Devbox tips?

  • add your user to the docker group
    sudo usermod -aG docker ${USER}
    • comes at a cost of security
  • ./bin/dev profile
  • Commit with dev git commit -v if you use GrumPHP

Devbox thanks?

Len Lorijn (symfony)

Peter Jaap Blaakmeer (magento2)

Caroga (Silex)

Berkan Duzgun (MacOS)

Elze Kool (fpm upstream)

Oscar Recio (MacOS)

Devbox questions?

$ dev down

Stopping development_web_1 ... done
Stopping development_php5_1 ... done
Stopping development_php71_1 ... done
Stopping development_php_1 ... done
Stopping development_redis_1 ... done
Stopping development_mailcatch_1 ... done
Stopping development_blackfire_1 ... done
Stopping development_db_1 ... done
Removing development_web_1 ... done
Removing development_php5_1 ... done
Removing development_php71_1 ... done
Removing development_php_1 ... done
Removing development_redis_1 ... done
Removing development_mailcatch_1 ... done
Removing development_blackfire_1 ... done
Removing development_db_1 ... done
Volume dockerdev-mysql-volume is external, skipping

Thanks

Devbox with docker

By Jeroen Boersma

Devbox with docker

  • 1,484