Drupal Docker Compose dev stack.
Switch branches/tags
Nothing to show
Clone or download
Jean Valverde
Jean Valverde Fix documentation
Latest commit 93e05f1 Sep 17, 2018


Drupal 8 Docker Compose Development


Full Linux support. Tested daily on Ubuntu 16/18.

Windows support is very, very limited due to Docker for Windows permissions problems and no privileged support :(

Mac support is very limited due to the fact that I don't have a Mac!


Based mostly on Docker official images and lightweight Alpine Linux to ease maintenance.

The purpose is to give flexibility in managment, try to rely as much as possible on offcial tools to avoid any new custom patterns. If you have to learn the meta tool instead of the tool, then it's not a good one...

This stack is not a one line command but more for users with a good dev-op level and knowledge on each technology used.

See other great project for a Docker based development:


Every service is optional as declared in the yml file.

Database management

Quick launch new Drupal 8 project

# Clone this project.
git clone https://github.com/Mogtofu33/docker-compose-drupal.git docker-drupal
cd docker-drupal

# Create your docker compose file from template.
cp docker-compose.tpl.yml docker-compose.yml

# (Optional) choose a db, remove or add services, add your composer cache folder.
# But you can let it as it for a default quick stack.
vi docker-compose.yml

# Create your config file from template.
cp default.env .env

# Edit your configuration if needed, recommended on Unix add your local uid/gid.
vi .env

# Check the yml file and fix if there is an error message.
docker-compose config

# For an existing Drupal 8 project, create folders and copy it in data/www
# Note that based on Composer template web root must be under drupal/web
# folder. If not you need to adapt Apache vhost config from
# config/apache/vhost.conf
mkdir -p data/www/drupal
cp -r _YOUR_DRUPAL_ data/www/drupal/

# For MySQL, copy your database dump uncompressed in ./data/dump/*.sql, it
# will be automatically imported on the first run.

# Launch the containers (first time include downloading Docker images).
docker-compose up --build -d

# Quick check logs to ensure startup is finished, mostly Apache.
docker-compose logs apache

Note: If you have a permission denied from it's probably because of owner of /var/run/docker.sock, run docker and docker-compose commands as sudo.

Access the minimal dashboard

If you have copy an existing Drupal project, you can import the database from the adminer link in the dashboard.

Setup Drupal 8 with Composer

Code download

Setup a new Drupal 8 based on a composer template (yes it's slower, but this is the good way!) with user Apache.

Based on Drupal 8 template, include Drush and Drupal console, using Composer in the docker service:

docker exec -it -u apache dcd-php \
    composer create-project drupal-composer/drupal-project:8.x-dev \
    /var/www/localhost/drupal --stability dev --no-interaction

OR locally if you have Composer installed, from this project root:

composer create-project drupal-composer/drupal-project:8.x-dev data/www/drupal --stability dev --no-interaction

Install Drupal 8

To use PostGreSQL change mysql to pgsql

You can replace standard by an other profile as minimal or demo_umami for Drupal 8.6+.

docker exec -it -u apache dcd-php /var/www/localhost/drupal/vendor/bin/drush -y si standard \
    --root=/var/www/localhost/drupal/web \
    --account-name=admin \
    --account-pass=password \

Access your Drupal 8

Login with admin / password:

Daily usage, add some modules

docker exec -it -u apache dcd-php \
    composer --working-dir=/var/www/localhost/drupal require \
    drupal/admin_toolbar drupal/ctools drupal/pathauto drupal/token drupal/panels

Enable some modules

docker exec -it -u apache dcd-php \
    /var/www/localhost/drupal/vendor/bin/drush -y en \
    --root=/var/www/localhost/drupal/web \
    admin_toolbar ctools ctools_block ctools_views panels token pathauto

Run a command on the server

docker exec -it -u apache dcd-php \
    ls -lah /var/www/localhost/drupal/web

Reset the stack

Destroy containers (data/ is persistent, so you are not loosing db or files)

docker-compose stop && docker-compose down

Remove your persistent data (and lost everything!)

rm -rf data

OR Only the database

rm -rf data/databases

Ubuntu/Linux helpers

For Ubuntu (16+) or Linux you can find in scripts/ multiple helpers to quickly run some daily commands from root folder, and drush/drupal links at the root.

# Run drush or drupal within the container
./drush status
./drupal site:status
# Run a bash command in the Php container
scripts/dcmd ls -lah /var/www/localhost
# Quickly dump/restore/drop your DB
scripts/mysql --help
scripts/pgsql --help
# Run composer as a service without local installation
scripts/composer --help
scripts/composer status

Suggested tools

You can find a script for Linux in scripts/get-tools.sh folder to download or update all tools:

chmod +x scripts/get-tools.sh
./scripts/get-tools.sh install


Windows support very partial, before running docker-compose you must run in Powershell:


Some permissions and privileged problems, so my Dashboard can not access docker.sock.

Build and testing (dev only)

make run-test