Setting up a drupal site on docker

This is moby dock

Content off this presentation

  • What is Docker?
  • The reasons to use (or not use) Docker
  • Setting up a site in Docker
  • Usefull commands
  • Live demo

What is Docker?

Docker is a tool designed to make it easier to create, deploy and run applications (in our case web applications) by using containers.

 

It's a bit like a virtual machine, but for you don't need to create a whole virtual operating system, and docker does not require the same memory usage as a complete virtual machine. 

The reasons to use (or not use) Docker

The reasons to use it

  • New employees don't need to install a complete local environment.
    • No more welcome to Dropsolid, your first day will be installing your local environment
  • Everyone has the same version off OS, mysql, php, ...
    • Im' the only one on windows/linux, how can I install this?
    • But I can't upgrade my php to version 7, I need version 5 for ...
    • So it works on my environment, but not on yours?
  • ​Once a project is done, you can delete it very quick
    • ​No more deleting files, database, solr, other leftover things
  • ​You've bought a new laptop, no more losing time setting up everything.

The reasons not to use it

  • Not good for production (less stable)
  • Docker doesn't work well with mysql dumps
  • At the moment not possible to use with local environment
  • First setup is complex?

Setting up a site in Docker

  • Installing docker
  • Dockerfile
  • docker-compose.yml

Download and install Docker

Dockerfile

Creates an image (a filesystem and parameters to use at runtime), this should never change.

Allways named Dockerfile, with capital.

Most common file structure.

Dockerfile

# The base image to start from, can be found on hub.docker.com
FROM php:apache

# Setup variables that can be used in the Dockerfile, and can be changed in the docker-compose.yml
ENV DRUPAL_VERSION 8.2.6
ENV DRUPAL_MD5 57526a827771ea8a06db1792f1602a85


# Execute commands, here it's installing some things
RUN apt-get update && apt-get install -yq \
    libfreetype6-dev \
    libjpeg62-turbo-dev \
    libmcrypt-dev \
    libpng12-dev \
    libicu-dev

RUN docker-php-ext-install gd json intl pdo pdo_mysql mbstring

# Change the current directory
WORKDIR /var/www/html

# We download the drupal code. and execute it
RUN curl -fSL "https://ftp.drupal.org/files/projects/drupal-${DRUPAL_VERSION}.tar.gz" -o drupal.tar.gz \
	&& echo "${DRUPAL_MD5} *drupal.tar.gz" | md5sum -c - \
	&& tar -xz --strip-components=1 -f drupal.tar.gz \
	&& rm drupal.tar.gz \
	&& chown -R www-data:www-data sites modules themes \

dockercompose.yml

Describes a container (running instance of an image) in its running state. 

version: '2'
services:
  web:
    build: .docker/web
    ports:
      - "80:80"
    volumes:
      - ./docroot:/var/www/html
  drush:
    image: drush/drush
    volumes_from:
      - web
  db:
    image: mysql
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=demo
      - MYSQL_USER=demo
      - MYSQL_PASSWORD=demo204125
    ports:
      - "3306:3306"
version: '2'
services:
  web:
    build: .docker/web
    ports:
      - "80:80"
    volumes:
      - ./docroot:/var/www/html
  drush:
    image: drush/drush
    volumes_from:
      - web
  db:
    image: mysql
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=demo
      - MYSQL_USER=demo
      - MYSQL_PASSWORD=demo204125
    ports:
      - "3306:3306"

This is one container

version: '2'
services:
  web:
    build: .docker/web
    ports:
      - "80:80"
    volumes:
      - ./docroot:/var/www/html
  drush:
    image: drush/drush
    volumes_from:
      - web
  db:
    image: mysql
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=demo
      - MYSQL_USER=demo
      - MYSQL_PASSWORD=demo204125
    ports:
      - "3306:3306"

Use image from dockerFile

Ports to open from container to local system

Mount the directory /var/www/html to your

pc in the docroot folder.

Use image from hub.docker.com

Use the same volumes as the web container

Overwrite the ENV variables from the Dockerfile

Usefull commands

  • "docker-compose build" to create an image from a Dockerfile
  • "docker-compose up -d" run the docker-compose.yml file to run your environment, -d is to run in the background
  • "docker ps" shows all the running containers on your system
  • "docker-compose ps" shows the containers for the current compose file
  • "docker-compose run drush" execute drush
  • "docker-compose run console" execute drupal console

Removing docker instances

  • Docker-compose kill *instancename*

  • Docker rm *instancename*


  • You can find the instancename with ps.

LIVE DEMO TIME

Setting up a drupal site on docker

By Brent Gees

Setting up a drupal site on docker

  • 181
Loading comments...

More from Brent Gees