Drupal 8 Docker

broken image


In this video, we are going to install Drupal 8 with the help of composer and docker4drupalIf you liked this video, please also have a look at my new course. In this tutorial, we are going to check how to install Drupal 8 with the help of drupal-composer and docker4drupal projects. We will create composer based Drupal project and we will configure and build Docker containers on which we will run Drupal 8. Tess, also known as socketwench, is a devops engineer who has worked with Drupal for over a decade. She is the author of the Flag module for Drupal 8 and has given sessions at DrupalCons and DrupalCamps throughout the world on Drupal 8 development, Docker,. The Drupal 8 implementation also adds an additional tool that allows you to locate the template that outputs the markup. Warning: turning on Twig debug can break some parts of the site, especially Views.

In this tutorial, we are going to check how to install Drupal 8 with the help of drupal-composer and docker4drupal projects. As you know from the 8th version of Drupal it is highly recommended to use composer for your setup and the drupal-composer project is the recommended structure. My personal structure is slightly improved but is also inspired by the drupal-composer project ( I will present that in a different article ).

Drupal 8 Docker Image

How to install composer and docker you may find here and here. Also, you would have to have git installed.

So let's start with some words about the two projects - first drupal-composer is a perfect kickstart that will help you to easily maintain your module dependencies in Drupal 8 with the help of composer. We will not get into too many details about it, as the project Github page covers it pretty well.

Regarding the docker4drupal project - it is a docker compose oriented setup that presets definitions of several Docker containers that are needed in order to build and have a functional development environment literally in minutes.

Drupal 8 Docker Tutorial

Docker
Docker

Let's start with creating our drupal-composer setup. In order to do that you may just change from the terminal to the folder where you have your Drupal projects and execute the following:

this will create a folder, called drupaltuto with the content of the drupal-composer boilerplate. As a folder structure it should look something like this:

This means we have our Drupal codebase prepared and built. Let's now go ahead and take care of building a server where we could install, test and further develop our Drupal 8 project. As we said we will use the docker4drupal. If we go to the GitHub page of the project and get the GitHub link to it we can just clone it in another folder like this:

Then we could just remove the .git file and then copy the content of the drupal_docker_server into the drupaltuto folder like this:

It is time to change a bit the docker_compose.yml file in order to have it ready for our project structure. Basically, we have declared all the containers that we will create and they will be connected internally and will be part of an environment on which we will run our Drupal 8 projects.

If we start with the PHP container - there is a possibility to have directly Drupal installed but I like more the idea of having a PHP, let's say 7.x there and that we have our Drupal codebase handled by our neat drupal composer project setup. So in the lines of the PHP container - we would comment out the image with the Drupal and we will uncomment a PHP image. Also, we will change the volumes path so that it starts from the current folder. It will look like this:

Also for the nginx volumes, we could change the volumes as well:

Drupal 8 Docker Production

And for accessing the built containers I like to change the ports to 8888 like this:

and we are ready to build. We would start Docker and then open the terminal.

In the terminal, we would have to make sure we are in the drupaltuto folder and we could build all the containers like this:

After it is ready we could check which containers are built with

Afterwards, we could access our Drupal install screen by going to http://drupal.docker.localhost:8888

How it worked so smooth you would ask... Well, the drupal composer project is creating a folder structure where there is a web folder, containing the whole Drupal codebase and the PHP and Nginx containers are expecting the web folder in the root folder too. As we merged the two projects - it is there and you are able to access it directly under http://drupal.docker.localhost:8888

Drupal 8 Dockery

And the last important bit that you have to know when installing is that when you are on the screen where you input the database cridentials - you would have to use the ones specified in the docker_compose.yml :

as for inputting the host - you would have to click on advanced when you are on the screen with the database credentials.

Drupal 8 Dockers

If you want to compare something - feel free to check the code from the example on our GitHub page and also you may see the whole process in this video.





broken image