Back to top

Testing a new Drupal 8 installation with 2 Docker commands

While I was mentoring GSoC 2015 Hawk Auth project, we wanted to test the project in D8 sandbox often. doesn't help here, because Hawk Auth uses Composer Manager to download extenal PHP library. (Another project using this set up is Commerce for D8.) There is an issue of supporting Composer in queue, but it hasn't been followed up.

Therefore, we tried to use Docker to spin up a new Drupal installation. It was very fast and simple. Below is the documentation:

Step 0: Install Docker

Step 1: Spin up a database

docker run --name drupaldb -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=drupal -d mariadb

(here we created a docker container called "drupaldb" using "mariadb" image, then we created a database "drupal" and set root password to be "password")

Step 2: Spin up Drupal 8

docker run --name d8docker --link drupaldb:mysql -p 80:80 -d drupal:8.1.8

(here we created a docker container called "d8docker" using "drupal:8.1.8" image, then used port 80 on localhost for access and linked to the database container we just created)

Done. Now, you can open localhost or on your browser to install Drupal into the database. If your localhost port 80 is being used, then you can change this section "80:80" in the above command to something like "1234:80", which will use port 1234 on your localhost.

Step 2.1: if you need to access the terminal of the D8 website container

docker exec -ti d8docker bash

(once you in, execute "export TERM=xterm" in your terminal for using text editor)

Step 2.2: if you want to read the log

docker logs -f d8docker

Step 3: Cleaning up

docker stop d8docker
docker stop drupaldb
docker rm -v d8docker
docker rm -v drupaldb


Have you tried...


Have you tried docker-compose, that makes it a breeze to link multiple containers together.

You just write a little YML file, and then you just say "docker-composer up" and you are good to go.
You can see an example here:

Drupal connection settings


Drupal connection settings:

Database type: MySQL, MariaDB, Percona Server or equivalent
Database name: drupal
Database username: root
Database password: password
Host: drupaldb
Port number: 3306

database host name


Thank you, that wasn't completely obvious to me, especially the "Host: drupaldb" setting.

Add new comment