Docker basics.How-to For Drupal devs
Hi @here!I am Taras KyryliukI am here because I have been using Docker for almost a Year and have something to say about it#
Disclaimer: I am a Drupal developer and automation maniac
OverviewSoftware isolationIntroducing DockerDocker in Drupal development#
Why we need Software Isolation?Starting from the assumption that software will always have bugs, we need a way to isolate and neutralize the effects of the bugs internet#
#VirtualizationOperating system-levelContainersOpenVZ, Solaris Zones, lxc, libcontainerHardware-levelVirtual machinesKVM, Xen, VMware, VirtualBox, xhyve
Operating system-level virtualization - ContainerisationLimited overheadDo not require a hypervisor layerAllow a greater density of containers to run on a hostCan be complex, hard to set up, and difficult to manage and automateCan run the same or a similar guest operating system as the host machine#
Hardware virtualizationLarge overhead because of hypervisor layerEasy to run and manageCan run any operating system#
#2. Introducing Docker
Docker is an open-source engine that automates the deployment of applicationsinto containers.#
Docker containers wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment.
The Docker client and serverDocker ImagesRegistriesDocker Containers#Docker components
Images are the building blocks of the Docker world.https://www.dockerbook.comWays to create images:Building an image from a DockerfileUpdating and committing an imageDocker images#
#Building an image from a Dockerfile
#Building an image from a Dockerfile
$ docker build -t tutorial/nginx .
Updating and committing an imageRun container:$ docker run -t -i training/sinatra /bin/bashInstall what you need:$ root@0b2616b0e5a8:/# apt-get install -y ruby2.0-dev$ root@0b2616b0e5a8:/# gem2.0 install jsonCommit changes:$ docker commit -m "Added json gem" -a "Kate Smith" 0b2616b0e5a8 ouruser/sinatra:v2https://docs.docker.com/engine/tutorials/dockerimages/
Docker Hub (public and private repositories)Own private registryHosted private registryDocker registries#
Run first container#
Container ports magic#Host OS8080Container with Nginx80
3. Docker in Drupal developmentWhat problems we can solve using it.#
Docker use casesUse container as a ServiceUse container as a toolRun one host Drupal project with Docker ComposeRun own cloud with Docker Swarm#
Container as a Service(MySQL as an example)Run:$ docker run -d --name=example-mysql --env="MYSQL_ROOT_PASSWORD=mypassword" mysql
Get IP:$ docker inspect example-mysql
Install Mysql Client:$ apt-get install mysql-client
Profit:$ mysql -uroot -pmypassword -h 172.17.0.20 -P 3306mysql>#http://severalnines.com/blog/mysql-docker-containers-understanding-basics
Container as a Service(MySQL as an example)#
Use container as a tool(PHPUnit as an example)#https://hub.docker.com/r/phpunit/phpunit/cd to folder with tests and Run:
$ docker run -v $(pwd):/app --rm phpunit/phpunit run
Profit!No need to installChoose any versionCan use different versions for different projects
DEV-STAGE-PROD env with Docker ComposeCompose is a tool for defining and running multi-container Docker applications.
With Docker Compose, we define a set of containers to boot up, and their runtime properties, all defined in a YAML file.#
DEV-STAGE-PROD env with Docker ComposeYou should have set of Compose-files for different environments.docker-compose.ymldocker-compose.override.ymldocker-compose.dev.ymldocker-compose.ci.ymldocker-compose.prod.yml
Run site with different commands.
Local:$ docker-compose up -dDev: $ docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
See more: https://docs.docker.com/compose/extends/ #
Own cloud with Docker Swarm modeSince Docker 1.12 it supports clustering out of the box
It turns a pool of Docker hosts into a single virtual Docker host
By the way!You can forget about server provisioning!
All you need is Docker installed on any Linux distro!#
THANK YOU!You can find me at:email@example.com