Using Docker with Drupal - Introduction
1.1K

Docker is an open platform for developing, shipping, and running applications.
| When | Who | License | GH stars |
|---|---|---|---|
| 03/2013 | Solomon Hykes | Apache | 37k |
It is the primary user interface to Docker. It accepts commands from the user and communicates back and forth with a Docker daemon.
It runs on a host machine. The user does not directly interact with the daemon, but instead through the Docker client with the RESTful api or sockets.
A Client with a Daemon as also as the docker-compose tool. Usually referred simply as "docker".

It creates servers (locally, on cloud etc), installs Docker on them, then configures the Docker client to talk to them.

A tool for defining and running complex applications with Docker (eg a multi-container application) with a single file.

Swarm pools together several Docker hosts and exposes them as a single virtual Docker host (cluster). It scale up to multiple hosts.

A (hosted) service containing repositories of images which responds to the Registry API.

docker run -i -t ubuntu:15.04 /bin/bash
/bin/bash)Screencast: Steps of a Docker workflow.



A Dockerfile is a text document that contains all the commands a user could call on the command line to create an image.
docker pull ubuntu
docker run -it --name ubuntu_example ubuntu /bin/bash
Screencast: SSH into a container
// General info
docker help // docker help run
docker info
docker version
docker network ls
// Images
docker images // docker [IMAGE_NAME]
docker pull [IMAGE] //
docker push [IMAGE]
docker save [IMAGE] // commit, tag, export, load, rmi
// Containers
docker run ...
docker ps // docker ps -a, docker ps -l
docker stop/start/restart [CONTAINER]
docker stats [CONTAINER]
docker top [CONTAINER]
docker port [CONTAINER]
docker inspect [CONTAINER]
docker inspect -f "{{ .State.StartedAt }}" [CONTAINER]
docker rm [CONTAINER]
Screencast: Common Docker commands
Let's create a Drupal app (apache, php, mysql, drupal)
docker pull drupal:8.2.3-apache
docker pull mysql:8
// Start a container for mysql
docker run --name mysql_example \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_DATABASE=drupal \
-e MYSQL_USER=drupal \
-e MYSQL_PASSWORD=drupal \
-d mysql:8
// Start a Drupal container and link it with mysql
// Usage: --link [name or id]:alias
docker run -d --name drupal_example \
-p 8280:80 \
--link mysql_example:mysql \
drupal:8.2.3-apache
// Open http://localhost:8280 to continue with the installation
// On the UI for the db host use: mysql
// There is a proper linking
docker inspect -f "{{ .HostConfig.Links }}" drupal_example
Screencast: Docker: Drupal and MySQL containers linked
Let's mount local files to a docker container
cd ~/drupalcamp2016
drush dl drupal-8.2.3
cd ~/drupalcamp2016/drupal-8.2.3
// Start a container for mysql
docker run --name mysql_container \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_DATABASE=drupal \
-e MYSQL_USER=drupal \
-e MYSQL_PASSWORD=drupal \
-d mysql:8
// Start drupal container with volume
// Folder "modules" locally is mounted to the container
docker run -d --name drupal_with_mysql_volumed \
-p 8290:80 \
--link mysql_container:mysql \
-v $(pwd)/modules:/var/www/html/modules \
drupal:8.2.3-apache
// Locally download devel module (assuming you have drush on host)
drush dl devel
// Devel module is available on the container
Let's create a Drupal app using docker-compose.yml
git clone [email protected]:theodorosploumis/drupalcamp2016.git \
~/drupalcamp2016/presentation
cd ~/drupalcamp2016/presentation/examples/docker-compose/simple
// Run docker-compose using the docker-compose.yml
docker-compose up -d
Screencast: Docker compose simple example
Drupal + friends together.
cd ~/drupalcamp2016
git clone [email protected]:theodorosploumis/drupal-docker.git
cd ~/drupalcamp2016/drupal-docker
docker-compose up -d
// Open http://localhost:8082 (web)
// Open http://localhost:8090 (phpmyadmin)
// Prepare Drupal for installation
docker exec drupal_8082 bash /scripts/prepare-install.sh
// Install with Drush
docker exec drupal_8082 drush \
site-install -y standard \
--site-name="Drupal 8 with Docker - Drush" \
--db-url=mysql://drupal:drupal@mysql/drupal \
[email protected] \
--account-name=admin \
--account-pass=admin \
[email protected]
Screencast: Drupal & PhpMyAadmin, Drush, Console etc
cd ~/drupalcamp2016
git clone [email protected]:theodorosploumis/drupal-docker.git
cd ~/drupalcamp2016/drupal-docker
docker-compose up -d
// Continue as before and install Drupal with drush...
// Scale the Drupal slave service
docker-compose scale drupal_slave=10
// Show the new slave containers IP Addresses
docker exec drupaldocker_drupal_slave_1 hostname -I
// Show the IP Address using Docker
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' \
drupaldocker_drupal_slave_1
...
// Slaves share the same mysql and files
docker exec drupaldocker_drupal_slave_1 drush status
docker exec drupaldocker_drupal_slave_2 drush status
...
Screencast: Scale Drupal with docker-compose
The Drupal "parts"
| A/a | Part | Docker options |
|---|---|---|
| 1 | Server | Image |
| 2 | Code | Image, Volumes, Inside 1 |
| 3 | Files | None (stage_file_proxy), Image, Inside 2 |
| 4 | Database | Image, Inside 1 |
| 5 | Helpers | Image, Inside 1, Volumes, None |


There are known best practices (see a list at examples/tips)
| Type | Software |
|---|---|
| Cluster & orchestrate | Swarm, Kubernetes, Marathon, MaestroNG, decking, shipyard |
| Registry | Portus, Docker Distribution, docker hub, quay.io, Google Container Reg., Artifactory, projectatomic.io, Treescale.com, Canister.io |
| PaaS | Rancher, Tsuru, dokku, flynn, Octohost |

$this->send('feedback');
Content type
Image
Digest
Size
8.6 MB
Last updated
almost 9 years ago
docker pull tplcom/drupalcamp2016