How to Install Docker for Drupal and use Composer to download the Code

Man near keyboard

How to install Drupal 8

Drupal 8 is open-source and it can easily be set up on your local environment using Docker4Drupal. Here Im going to guide you how to set it up on your development environment:

First you need to set up in your local development environment all the Docker Containers such as MariaDB, PHP, nginx, mailhog, pma, portainer and traefik:

I made my setting available on my Github Account for Maria Consulting web site.

Drupal 8 is built using Composer Install. Clone my repository, before running compose install, first change your web site settings inside .env:



Note: Somehow the extension for your development web site must be ".local" otherwise the Browser will not trust the connection (if you try to use for example ".dev") because the site usually run on the 8080 port which I set it up for the traefik container, this port works well with ".local" or ".localhost"

    image: traefik:v2.0
    container_name: "${PROJECT_NAME}_traefik"
    command: --api.insecure=true --providers.docker
      - '8080:80'
      - /var/run/docker.sock:/var/run/docker.sock

Place inside composer.json all the contributed modules that need to be installed and remember that they do not need to be kept in Git as the Core /drupal/web/core and /drupal/vendor folders. For example my .gitignore file looks like:

# Ignore directories generated by Composer

I always keep inside my composer.jon all these very useful modules such as: Capthca, Code Snippet, Cookie Consent, Features, Ctools, MetaTag, simple sitemap, Webform, Token, Path auto, Bootstrap theme (version 3.21) so that each time I start a new Drupal 8 my composer json looks like:

    "require": {
        "php": ">=7.0.8",
        "composer/installers": "^1.2",
        "cweagans/composer-patches": "^1.6.5",
        "drupal/backup_migrate": "^4.1",
        "drupal/block_visibility_groups": "^1.3",
        "drupal/bootstrap": "^3.21",
        "drupal/captcha": "^1.0",
        "drupal/codesnippet": "^1.6",
        "drupal/console": "^1.0.2",
        "drupal/cookieconsent": "^1.4",
        "drupal/core": "^8.8.0",
        "drupal/core-composer-scaffold": "^8.8.0",
        "drupal/ctools": "^3.4",
        "drupal/devel": "^2.1",
        "drupal/ds": "^3.5",
        "drupal/features": "^3.8",
        "drupal/field_group": "^3.0",
        "drupal/flexslider": "^2.0@beta",
        "drupal/layout_plugin": "^1.0@alpha",
        "drupal/libraries": "^3.0@alpha",
        "drupal/metatag": "^1.12",
        "drupal/migrate_source_csv": "^3.3",
        "drupal/migrate_tools": "^4.5",
        "drupal/migrate_upgrade": "^3.1",
        "drupal/module_filter": "^3.1",
        "drupal/pathauto": "^1.6",
        "drupal/prism": "^1.0",
        "drupal/simple_sitemap": "^3.6",
        "drupal/token": "^1.6",
        "drupal/webform": "^5.9",
        "drush/drush": "^9.7.1 | ^10.0.0",
        "vlucas/phpdotenv": "^4.0",
        "webflo/drupal-finder": "^1.0.0",
        "zaporylie/composer-drupal-optimizations": "^1.0"
    "require-dev": {
        "drupal/core-dev": "^8.8.0"

If you need more contributed module you can add them using composer, for example this is the way I added these 2 modules:

composer require drupal/cookieconsent
composer require drupal/simple_sitemap

Voila, only what you need to run is:

composer install

After the installation check that Composer create the following folders:


In order to complete the installation you need the Data Base credential and run the PROJECT_BASE_URL/install.php In my Project I use Bootstrap version 3.2 and I set up a sub-theme inside maria_consulting.

Note: After you uploaded all files (for D8 you also need to upload the vendor folder) on the server you need to make sure that the /sites/default directory has got written permission, the private folder must be outside htdocs, then the installer will ask you the data base details, you need to specify the data base user and password. Please check the Admin Reports status to see it everything went well: /admin/reports/status

In my D8 installation, in order to resolve 2 security warnings it was advising to set these 2 variables in the settings.php:

// Outside Doc Root folder to make it private
$settings['file_private_path'] = $app_root . '/../private';

// Set up your trusted hosts:
$settings['trusted_host_patterns'] = [
   '^www\.maria-consulting\.local$', '^maria-consulting\.local$',

and in settings.php the database connection are the end of the file:

$settings['config_sync_directory'] = '../config/sync';
$databases['default']['default'] = array (
  'database' => 'drupal',
  'username' => 'drupal',
  'password' => 'drupal',
  'prefix' => '',
  'host' => 'mariadb',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',

As you can see, it contains the values which I entered inside the .env file:


If you have any questions on how to set it up, please contact us.

1. Support

teamwork brainstorming meeting and new startup project in workplace

Groups organise, meet, and work on projects based on interest or geographic location. It\'s a great way to get involved, learn more and get support.

2. Migrate

digital conceptual business technology background arrows chip

Migrate Drupal by follow our very simple Six Steps! Set up your YML configuration to define your custom migrate modules to import data from Drupal 7.

3. Custom

businessman using tablet

If you cannot find a module that does exactly what you need then need to write a custom module. First try to find the same functionality..

4. Example

reviewing financial reports in returning on investment analysis

Plan your strategy to use Drupal at the best of its capability and performance. As Drupal is written in PHP it requires that a module is..