Skip to content

betoscopio/docker4drupal

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Docker-based 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.

Overview

The Drupal bundle consist of the following containers:

Container Service name Volume Port Enabled by default
Nginx nginx 8000
PHP 7, 5.6 php ./
MariaDB mariadb ./docker-runtime/mariadb
phpMyAdmin pma 8001
Mailhog mailhog 8002
Redis redis
Memcached memcached
Apache Solr solr ./docker-runtime/solr 8003

PHP, Nginx and MariaDB 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.

Instructions

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. 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:

DRUPAL_VERSION: 8

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) her

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.

Containers

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).

PHP

Currently PHP version 5.6 and 7 are provided. Check out the instructions (step 5) to learn how to switch the version.

Drush

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

Composer

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

Xdebug

If you want to use xdebug, uncomment the following line in the compose file:

#    XDEBUG_CONFIG: xdebug.remote_autostart=1

See the known issue with Xdebug in Mac OS.

MariaDB

Import

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

Export

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

Redis

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';

Memcached

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');

Mailhog

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.

phpMyAdmin

By default, container with phpMyAdmin included in the bundle. You can accessit 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

Logs

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

Status

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

Going beyond local machine

Check out Wodby if you need optimized consistent docker-based environment for Drupal on your dev/staging or production servers.

About

Native docker-based environment for Drupal

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%