Skip to content

mogtofu33/docker-compose-drupal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Drupal 8 Docker Compose Development

pipeline status

Full Linux support. Tested daily on Ubuntu 16+.

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!

Requirements

Recommended

Description

What's this?

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

This stack is meant to be used as a single Drupal 8 project only with quick setup, run and destroy workflow.

The purpose is to give flexibility in management, try to rely as much as possible on official tools to avoid any new custom patterns.

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

Services included

Every service is optional as declared in the yml file.

Database management

Quick demo (Ubuntu)

Get this project

wget https://gitlab.com/mog33/docker-compose-drupal/-/archive/master/docker-compose-drupal-master.tar.gz
tar -xzf docker-compose-drupal-master.tar.gz
cd docker-compose-drupal-master

Install this stack with minimal services, download and install Drupal 8 with profile Demo Umami

make demo

Installation and configuration

Project installation

Grab this project

wget https://gitlab.com/mog33/docker-compose-drupal/-/archive/master/docker-compose-drupal-master.tar.gz
tar -xzf docker-compose-drupal-master.tar.gz
cd docker-compose-drupal-master

Create your docker compose file from template

cp docker-compose.tpl.yml docker-compose.yml
cp default.env .env

Optional: Edit configuration

Recommended on Unix add your local uid/gid.

vi .env

Optional: Customize the stack

Choose a database, remove or add services, add your composer cache folder if needed on service php. Do not touch for a default quick stack.

vi docker-compose.yml

Check the yml file and fix if there is an error message

docker-compose config

Option 1: existing Drupal 8 project

Copy codebase

For an existing Drupal 8 project, copy it here in a folder named drupal.

So you have your composer.json file in drupal\composer.json

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

cp -r _YOUR_DRUPAL_ drupal

Import database

For MySQL, copy your database dump uncompressed in ./database/mysql-init/*.sql, it will be automatically imported on the first launch of the stack.

For PostgresSQL, copy your database dump uncompressed in ./database/pgsql-init/*.pg_dump, it will be automatically imported on the first launch of the stack.

If you want to manually import your database with adminer or included helper scripts with _Linux_you can skip this step.

Launch the stack

docker-compose up --build -d

Wait and check the import of your database dump with (change mysql to pgsql if needed)

docker-compose logs mysql

Access the minimal dashboard

Option 2: setup Vanilla Drupal 8 with Composer

Code download

Setup a new Drupal 8 based on a Composer project.

Based on Drupal 8 template, include Drush and Drupal console, using Composer locally:

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

Launch the stack

docker-compose up --build -d

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/vendor/bin/drush -y site:install standard \
    --root=/var/www/localhost/web \
    --account-name=admin \
    --account-pass=password \
    --db-url=mysql://drupal:drupal@mysql/drupal
    #--db-url=pgsql://drupal:drupal@pgsql/drupal

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 require \
    drupal/admin_toolbar drupal/ctools drupal/pathauto drupal/token drupal/panels

With Linux, you can use included helper script

scripts/composer 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/vendor/bin/drush -y en \
    --root=/var/www/localhost/web \
    admin_toolbar ctools ctools_block ctools_views panels token pathauto

With Linux, you can use included helper script

scripts/drush -y en 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/web

Access the server with bash

docker exec -it -w /var/www/localhost -u apache dcd-php bash

Reset the stack

Destroy containers

Note: ./drupal/ is persistent but NOT the database files!

Save your database under Linux

scripts/mysql dump
scripts/pgsql dump

Stop and remove containers

docker-compose down

Remove your persistent data (and lost everything!)

rm -rf data

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
scripts/drush status
scripts/drupal site:status
# 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

Install Drupal 8 variant helpers (This delete and replace existing Drupal in ./drupal folder)

scripts/install-drupal.sh
scripts/install-drupal.sh list
scripts/install-drupal.sh install -p drupal-demo

Upgrade

Because this project is mainly focused on a one time usage, there is currently no upgrade path and the best way to upgrade is to dump and copy your project to a new version of this project.

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

Troubleshooting

General problem

In case of any problem, first step is to check the configuration and the logs

docker-compose config
docker-compose logs

Port 80

If you have already a web server running on port 80 or 443 on your machine you must stop it or change APACHE_HOST_HTTP_PORT in .env

Windows

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

$Env:COMPOSE_CONVERT_WINDOWS_PATHS=1

Some permissions and privileged problems


Want some help implementing this on your project? I provide Drupal 8 expertise as a freelance, just contact me.