Trendtopic Docker: What you can do with it and how it is used for Drupal projects within Cocomore
Docker? What is Docker?
“Docker containers wrap up a piece of software in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in.”
- Lightweight: All containers running on a single machine share the same operating system kernel, so you can start several of them instantly and the resources of the machine will not notice the difference.
- IS open: Docker containers are based on open standards, having all major Linux distributions and Microsoft operating systems available.
- Secure: Containers isolate applications from each other and the underlying infrastructure.
What is the difference from other virtual machines?
What did we want to solve by using Docker in our projects?
- Accelerating the developer onboarding, also for external members.
- Ensuring that everyone on the team works with the same system configuration on different operative systems.
- Avoiding prior performance problems using other VM.
- Having reusable images ready for starting new projects.
- Having a repository with base images and being able to pull them for our projects.
Using Docker for Drupal projects
Our Docker image for Drupal projects
- Once you have defined your image in the dockerfile, you can build your image based on your dockerfile with:
$ docker build -t [YOUR IMAGE NAME]/drupal [PATH TO YOUR DOCKERFILE]
Our Drupal 8 boilerplate
Running the boilerplate within Docker
- Clone the Drupal 8 boilerplate:
$ git clone https://github.com/cocomore/drupal8-boilerplate.git new_d8_project
- Run a new Docker container and bind the Drupal project to it.
$ docker run -d -p 8080:80 --name new-d8-project -v ~/projects/new_d8_project:/var/www/drupal-project -t cocomore/drupal
- -p: Allows us to forward our local ports (8080) with the apache exposed port by the container (80).
- -v: Allows us to bind data volume from our local machine to the container. With this, we can edit our project files directly from the local machine and it will be reflected in the Docker container.
-t: The name of the Docker image from which we’ll run the new instance.
- Install your new Drupal project:
$ docker exec -i new-d8-project ./var/www/drupal-project/scripts/setup.sh
With those 3 steps we’ll have our new project installation running and you’ll have it available at
- Specifying a basic profile for the cocomore_profile with some basic modules and configurations. Currently we are using the same configuration as the standard profile.
- Using composer instead of drush make for building the contrib dependencies.
- Providing drush aliases for working with the different environments (local, staging...).
- Having Behat tests for a functional test coverage.
- Publishing a Docker image at Docker Hub, ready to use within the boilerplate.
Other interesting projects
Other interesting projects that aim to user Drupal within Docker are the following:
- Bowline: This is an interesting project that uses Docker Composer for setting up different Docker Containers and using Drupal Console to install your Drupal instance. It also provides
- Drupal Project: This project aims to manage all Drupal dependencies using composer instead of drush make. Many contributors are working on this project and it looks awesome.