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. Simplytest.me 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 Simplytest.me 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 127.0.0.1 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

Comments

Have you tried...

Comment: 

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: https://github.com/WiredPea/ddd

Drupal connection settings

Comment: 

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

Comment: 

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

Add new comment