This article introduces how to use Docker to install Drupal8 runtime environment

Form a complete set of video

## 1. About Docker

Docker is an open source application container engine that allows developers to package their applications and dependencies into a portable image that can then be distributed to any popular Linux or Windows machine, as well as virtualization. Containers are completely sandboxed and have no interface with each other.

Baidu Encyclopedia about Docker

About Drupal

Drupal is an open source content management Framework (CMF) written in PHP. It consists of a content management system (CMS) and a PHP development Framework (Framework). It has won the World’s Best CMS Award for many years running and is the most famous WEB application based on PHP. At the end of 2011, 13,802 WEB experts worked on Drupal development; Drupal is used by 729,791 web designers in 181 languages in 228 countries. Famous cases include: The United Nations, the White House, the Department of Commerce, the New York Times, Warner, Disney, Fedex, SONY, Harvard University, Ubuntu, etc.

Baidu Encyclopedia about Drupal

Drupal runtime environment

Apache (Recommended)

You can use Apache’s mod_rewrite to extend Drupal’s Clean url. In Drupal8, clean urls are turned on by default and cannot be turned off, so in order for Drupal to work properly, Mod_rewrite needs to be installed and enabled.

The virtual host must be configured to include AllowOverride All to allow Drupal. Htaccess files to work.

Database

MySQL 5.5.3/MariaDB 5.5.20/Percona Server 5.5.8 or higher with PDO and an InnoDB-compatible primary storage engine,

PostgreSQL 9.1.2 or higher with PDO,

SQLite 3.6.8 or who

PHP

Drupal 8: PHP 5.5.9 or higher

Three steps to get

See the configuration environment, many beginners will be discouraged. Thanks to Docker’s image and container technology, we can save ourselves the trouble of configuring the environment. Moreover, the environment can be identical to the live environment, saving us the trouble of deployment and maintenance.

Installing the Drupal8 runtime environment with Docker is a three-step process that requires two containers to be installed.

Step 1 Install the database

On the command line, enter the following command:

docker run \
-e MYSQL_ROOT_PASSWORD=admin \
-e MYSQL_DATABASE=drupal8 \
-e MYSQL_USER=drupal8 \
-e MYSQL_PASSWORD=drupal8 \
-v mariadb:/var/lib/mysql \
-d \
--name mariadb \
mariadb
Copy the code

The first line means to create the container, the second through sixth lines are the database configuration parameters, -d is to run the container in the background, –name gives the container a name, and the last line is the image name.

The full understanding is to create a container named Mariadb running in the background from the Mariadb image, following the specified database configuration parameters. If there is no mariadb image locally, the container is automatically pulled from the Docker Hub.

The running results are as follows:

Unable to find image 'mariadb:latest' locally
latest: Pulling from library/mariadb
5667fdb72017: Pull complete
d83811f270d5: Pull complete
ee671aafb583: Pull complete
7fc152dfb3a6: Pull complete
9f669c535a8b: Pull complete
a6de1092ee4e: Pull complete
ee37a2c88dd9: Pull complete
d927a3dd356c: Pull complete
d83c9d39c64f: Pull complete
1b0644883413: Pull complete
09a38adc2558: Pull complete
3c853415b952: Pull complete
2690cf0bfab9: Pull complete
3c68d64f060f: Pull complete
Digest: sha256:a32daf0281803fd96e86daf6b0293b4d476cede1b5ce80b18452dfa1405360ff
Status: Downloaded newer image for mariadb:latest
8cae72ad7ff02870c575c09eb3ad6f053c395287a3cfe17d7888991acc6cc254
Copy the code

Step 2 install the web server and Drupal source code

On the command line, enter the following command:

docker run \
--name drupal8 \
--link mariadb:mysql \
-p 80:80 \
-d \
drupal
Copy the code

The drupal image creates a container named Drupal8 that runs in the background. If no drupal image is available locally, the container is automatically pulled from the Docker Hub and then created. — Link connection named mariadb container (created in the first step), take a link named mysql, which will be used in the third installment of Drupal installation. Remember that! -p maps port 80 of the container to port 80 of the host. Then the browser of the host can directly access localhost.

The running results are as follows:

Unable to find image 'drupal:latest' locally
latest: Pulling from library/drupal
8f91359f1fff: Pull complete
bf2faaedf741: Pull complete
24cd1299a53e: Pull complete
17091cc665e4: Pull complete
ac9365919f9b: Pull complete
4f1b34e209ee: Pull complete
832757fa04a4: Pull complete
640a8cc59ee4: Pull complete
375d45a647bd: Pull complete
c265603c2115: Pull complete
b0b436e89a13: Pull complete
752098124903: Pull complete
baaf39033af6: Pull complete
eac75ead14e0: Pull complete
8494df29c26d: Pull complete
b9dd3d0f6cb9: Pull complete
Digest: sha256:899473656db6b2fb7343d9cfd8ab6493199b60500eed9d7202c0d2552c8c5b1d
Status: Downloaded newer image for drupal:latest
84d185875cd1e27c301042c743aab01757d3e9814557698b8d40a6b7b977e4ca
Copy the code

Since we did not specify a version number for the image when we installed the container, the latest version is automatically pulled, which means the latest version of the image.

After installing both containers, we can view containers and images in Docker. View containers:

docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
84d185875cd1        drupal              "Docker - PHP - entrypoi..."About an hour ago Up About an hour 0.0.0.0:80->80/ TCP drupal8 8cae72ad7ff0 mariadb"Docker - entrypoint. S..."   About an hour ago   Up About an hour    3306/tcp             mariadb
Copy the code

View mirror:

docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
drupal              latest              4ae9d94d03b6        3 days ago          453MB
mariadb             latest              92495405fc36        12 days ago         356MB
Copy the code

The third step is configuring the website

Type localhost in the browser of the host machine (which is our current computer) to start the Drupal installation page. Note the database connection configuration:

Drupal8 > drupal8 > drupal8 > drupal8 > drupal8 > drupal8 > drupal8