Docker-based Drupal stack


License: MIT

Language: Shell

Keywords: alpine, docker, docker-compose, drupal

Native docker-based local environment for Drupal

Use this Docker compose file to spin up local environment for Drupal with a native Docker app on Linux, Mac OS X and Windows.

Docker4Drupal is designed to be used for local development, if you're looking for a dev/staging/production solution check out Wodby. Use Wodby to deploy container-based infrastructure consistent with Docker4Drupal to any server.


The Drupal bundle consist of the following containers:

Container Service name Image Public Port Enabled by default
Nginx nginx wodby/drupal-nginx 8000
PHP 7 / 5.6 php wodby/drupal-php
MariaDB mariadb wodby/drupal-mariadb
phpMyAdmin pma phpmyadmin/phpmyadmin 8001
Mailhog mailhog mailhog/mailhog 8002
Redis redis redis/redis
Memcached memcached _/memcached
Solr solr _/solr 8003
Varnish varnish wodby/drupal-varnish 8004
SSHD sshd wodby/drupal-sshd 8006

PHP, Nginx, MariaDB and Varnish configs are optimized to be used with Drupal. We regularly update this bundle with performance improvements, bug fixes and newer version of Nginx/PHP/MariaDB.

All containers' images used in the bundle are either official or based on official with optimization for Drupal.


Feel free to adjust volumes and ports in the compose file for your convenience.

Supported Drupal versions: 7 and 8

Supported PHP versions: 7.x and 5.6.x.

1. Install docker for Linux, Mac OS X or Windows (10+ Pro). For Mac and Windows make sure you're installing native docker app version 1.12, not docker toolbox.

For Linux additionally install docker compose

2. Download the compose file from this repository and put it to your Drupal project codebase (you might want to add docker-compose.yml to .gitignore).

3. Since containers do not have a permanent storage, directories from the host machine (volumes) should be mounted: one with code of your Drupal project and another with database files.

By default, the directory with the compose file (volume ./) will be mounted to PHP container (assuming it's your codebase directory). Additionally docker-runtime directory will be created to store files for mariadb and, optionally, solr containers. Do not forget to add docker-runtime to your .gitignore file.

Linux only: fix permissions for your files directory with:

$ sudo chgrp -R 82 sites/default/files
$ sudo chmod -R 775 sites/default/files

4. Choose Drupal version by modifying the following environment variable (could be 7 or 8) in the compose file:


5. Choose PHP version by modifying the name of the image:

image: wodby/drupal-php:7.0 # Allowed: 7.0, 5.6

6. Update database credentials in your settings.php file:

database: drupal
username: drupal
password: drupal
host: mariadb

7. If you want to import your database, uncomment the following line in the compose file:

#      - ./docker-runtime/mariadb-init:/docker-entrypoint-initdb.d # Place init .sql file(s) here

Create the volume directory ./docker-runtime/mariadb-init in the same directory as the compose file and put there your SQL file(s). All SQL files will be automatically imported once MariaDB container has started.

8. If you need to deploy one of the optional containers (Redis, Memcached, Apache Solr) uncomment the corresponding lines in the compose file.

9. Now, let's run the compose file. It will download the images and run the containers:

$ docker-compose up -d

10. Make sure all containers are running by executing:

$ docker-compose ps

11. That's it! You drupal website should be up and running at http://localhost:8000.


Accessing containers

You can connect to any container by executing the following command:

$ docker-compose exec php sh

Replace php with the name of your service (e.g. mariadb, nginx, etc).


Nginx is being used as a web server. Nginx is pre-configured to be used with Drupal 7 and 8.


PHP is used with Nginx via PHP-FPM. Currently PHP version 5.6 and 7 are provided. Check out the instructions (step 5) to learn how to switch the version.


PHP container has installed drush. When running drush make sure to open the shell as user 82 (www-data) to avoid access problems in the web server, which is running as user 82, too:

$ docker-compose exec --user 82 php drush

Also, you can use preconfigured drush alias @dev:

$ docker-compose exec --user 82 php drush @dev


PHP container has installed composer. Example:

$ docker-compose exec --user 82 php composer update

Drupal Console

PHP container has installed drupal console. Example:

$ docker-compose exec --user 82 php drupal list


If you want to use Xdebug, uncomment this line to enable it in the compose file before starting containers:

PHP_XDEBUG_ENABLED: 1       # Comment out to disable (default).

If you would like to autostart Xdebug, uncomment this line:

PHP_XDEBUG_AUTOSTART: 1     # Comment out to disable (default).

Xdebug on Mac OS X

There are two more things that need to be done on Mac OS X in order to have Xdebug working. Uncomment PHP_XDEBUG_ENABLED to enable Xdebug and uncomment the following two lines:

PHP_XDEBUG_REMOTE_CONNECT_BACK: 0         # Disabled for remote.host to work (enabled by default)
PHP_XDEBUG_REMOTE_HOST: ""  # Setting the host (localhost by default)

It is also needed to have localhost loopback alias with IP from above. You need this only once and that settings stays active until logout or restart.

sudo ifconfig lo0 alias

For more details see the issue with Xdebug in Mac OS.



Many configuration options can be passed as flags without adjusting a cnf file. See example in the compose file:

#    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci


Check out the instructions (step 7) to learn how to import your existing database.


Exporting all databases:

docker-compose exec mariadb sh -c 'exec mysqldump --all-databases -uroot -p"root-password"' > databases.sql

Exporting a specific database:

docker-compose exec mariadb sh -c 'exec mysqldump -uroot -p"root-password" my-db' > my-db.sql


To spin up a container with Redis cache and use it as a default cache storage follow these steps:

  1. Uncomment lines with redis service definition in the compose file.
  2. Download and install redis module
  3. Add the following lines to the settings.php file:
$conf['redis_client_host'] = 'redis';
$conf['redis_client_interface'] = 'PhpRedis';
$conf['lock_inc'] = $contrib_path . '/redis/redis.lock.inc';
$conf['path_inc'] = $contrib_path . '/redis/redis.path.inc';
$conf['cache_backends'][] = 'sites/all/modules/redis/redis.autoload.inc';
$conf['cache_default_class'] = 'Redis_Cache';
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';


To spin up a container with Memcached and use it as a default cache storage follow these steps:

  1. Uncomment lines with memcached service definition in the compose file.
  2. Download and install memcache module
  3. Add the following lines to the settings.php file:
$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
$conf['lock_inc'] = 'sites/all/modules/memcache/memcache-lock.inc';
$conf['memcache_stampede_protection'] = TRUE;
$conf['cache_default_class'] = 'MemCacheDrupal';
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
$conf['memcache_servers'] = array('memcached:11211' => 'default');

Memcached Admin

To spin up a container with the Memcached Admin User interface uncomment to memcached-admin service definition. To get started visit http://localhost:8006/index.php


By default, container with mailhog included in the bundle. It will catch all email sent from the PHP container. You can view emails by visiting its admin UI on localhost:8002.


By default, container with phpMyAdmin included in the bundle. You can access it by localhost:8001

Apache Solr

To spin up a container with Apache Solr search engine uncomment lines with solr service definition in the compose file. Use volume directory ./docker-runtime/solr to access configuration files. Solr admin UI can be accessed by localhost:8003


To spin up a container with Varnish uncomment lines with varnish service definition in the compose file. Use the port specified in the compose file to access the website via Varnish.

Multiple projects

To use D4D with multiple projects simply adjust the ports in the compose file, e.g. instead of ports 8000, 8001, 8002 you can use 7000, 7001, 7002.


You can use docker4drupal containers for your test environment in your CI/CD workflow:

Docroot in subdirectory

If your docroot located in a subdirectory use options PHP_DOCROOT and NGINX_DOCROOT to specify the path (relative path inside the /var/www/html/ directory) for PHP and Nginx containers.


To get logs from a container simply run (skip the last param to get logs form all the containers):

$ docker-compose logs [service]

Example: real-time logs of the PHP container:

$ docker-compose logs -f php


We're actively working on this instructions and containers. More options will be added soon. If you have a feature request or found a bug please submit an issue.

We update containers from time to time, to get the lastest changes simply run again:

$ docker-compose up -d


Windows permissions problems


Windows interactive mode isn't supported


Why it slow on OS X?


Xdebug on OS X


Drupal Console issues


Project Statistics

Sourcerank 9
Repository Size 600 KB
Stars 887
Forks 420
Watchers 60
Open issues 45
Dependencies 0
Contributors 6
Tags 17
Last updated
Last pushed

Top Contributors See all

Pavel Prischepa Chingis martin frances Alan Bondarchuk Mladen Đurić herebebogans

Recent Tags See all

5.0.4 April 05, 2018
5.0.3 April 03, 2018
5.0.2 March 29, 2018
5.0.1 March 08, 2018
5.0.0 March 07, 2018
2.5.0 December 12, 2017
2.4.0 October 17, 2017
2.3.0 July 13, 2017
2.2.0 June 27, 2017
2.1.0 April 18, 2017
2.0.1 March 13, 2017
2.0.0 March 10, 2017
v1.3.0 December 21, 2016
1.3.0-rc1 December 20, 2016
1.2.0 August 09, 2016

Interesting Forks See all

Docker-based Drupal stack
Shell - Last pushed - 1 stars
Docker-based environment for Drupal
Updated - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2016-11-24 17:22:58 UTC

Login to resync this repository