Docker

We are using Docker for our local development environment. This provides us with a quick installation of all the necessary components and configurations needed to fully host and develop a site on our local machine. A docker folder with the docker-compose.yml file will be present in every project, meaning a new developer on the project should have minimal time starting.

A standardised solution also means every developer will be using the same stack and every project will be built on the same specification, meaning less time debugging and less time adjusting the project for each environment.

We are using Wodbys' Drupal stack which can be found at https://github.com/wodby/docker4drupal. There is also a very extensive documentation available at https://docker4drupal.readthedocs.io. Below you can find a quick guide on how to start it up and how to use it through the project lifespan.

Basic commands and usage

Here are some of the most used commands. Parentheses show the alias provided by out starter template.

Starting, stoping and removing Docker containers.

docker-compose start -d (dc-start)
docker-compose stop (dc-stop)
docker-compose down (dc-down)

Creating a Solr core inside the Solr server

docker exec -ti docker_solr_1 make core=core1 -f /usr/local/bin/actions.mk (dc-solr)

Using Drush and Drupal console

docker-compose exec php drush -r /var/www/html/web [DRUSH_COMMAND] (dc-drush [DRUSH_COMMAND])
docker-compose exec php drupal [DRUPAL_COMMAND] (dc-drupal [DRUPAL_COMMAND])

SSH into the container

docker-compose exec php sh (dc-ssh)

Starting fresh

Every project should have a docker folder at the root and then a docker-compose.yml file inside of that. And that is all that is needed. So the folder structure should look something like this:

root
    - docker
        - docker-compose.yml
    - vendor
    - web
    .
    .
    .

While the existing structure should work out of the box there are some adjustments to be made to make development a little more easier.

MariaDB

mariadb:
    image: wodby/mariadb:10.1-2.3.5
    ports:
      - 3308:3306
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: drupal
      MYSQL_USER: drupal
      MYSQL_PASSWORD: drupal
    volumes:
#      - ./mariadb-init:/docker-entrypoint-initdb.d # Place init .sql file(s) here.
      - ./database:/var/lib/mysql # I want to manage volumes manually.

Add the ports value so you can access the database from your host machine using a database GUI or PHPStorm through the 3308 (or any other value set here) port. Also uncomment one of the volumes, which will define that the database files should be saved inside the database folder. This helps you keep your database even if you completely remove the images.

PHP

php:
# 1. Images with vanilla Drupal – wodby/drupal:[DRUPAL_VERSION]-[PHP_VERSION]-[STABILITY_TAG].
#    image: wodby/drupal:8-7.1-3.0.0
#    image: wodby/drupal:8-7.0-3.0.0
#    image: wodby/drupal:7-7.1-3.0.0
#    image: wodby/drupal:7-7.0-3.0.0
#    image: wodby/drupal:7-5.6-3.0.0
#    image: wodby/drupal:6-5.6-3.0.0
#    image: wodby/drupal:6-5.3-3.0.0
# 2. Images without Drupal – wodby/drupal-php:[PHP_VERSION]-[STABILITY_TAG].
    image: wodby/drupal-php:7.1-3.0.0
#    image: wodby/drupal-php:7.0-3.0.0
#    image: wodby/drupal-php:5.6-3.0.0
#    image: wodby/drupal-php:5.3-3.0.0
    environment:
      PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025
      PHP_FPM_CLEAR_ENV: "no"
      DB_HOST: mariadb
      DB_USER: drupal
      DB_PASSWORD: drupal
      DB_NAME: drupal
      DB_DRIVER: mysql
      PHP_XDEBUG: 1
      PHP_XDEBUG_DEFAULT_ENABLE: 1
      PHP_XDEBUG_REMOTE_CONNECT_BACK: 0
      PHP_XDEBUG_REMOTE_HOST: "10.254.254.254"
#      PHP_XDEBUG_PROFILER_OUTPUT_DIR: /mnt/files/xdebug/profiler
#      PHP_XDEBUG_TRACE_OUTPUT_DIR: /mnt/files/xdebug/traces
    volumes:
#      - codebase:/var/www/html
## Options for macOS users (https://docker4drupal.readthedocs.io/en/latest/macos)
      - ../:/var/www/html:delegated # User-guided caching
#      - docker-sync:/var/www/html # Docker-sync
## For Xdebug profiler files
#      - files:/mnt/files

Here you should uncomment the proper image to use. Most of the cases you should be using images without Drupal and with PHP version of 7.0 and above. You should also uncomment anything to do with Xdebug, so you can use that for debugging while developing. And lastly you should uncomment one of the volumes for macOS users. Since we are in the docker folder, we want to map the whole project folder from the root, so we need to map '../'. Also make sure you use the :delegated flag at the end which will help you with file synchronisation performance.

Nginx

nginx:
# wodby/drupal-nginx:[DRUPAL_VERSION]-[NGINX_VERSION]-[STABILITY_TAG].
    image: wodby/drupal-nginx:8-1.13-3.0.1
#    image: wodby/drupal-nginx:7-1.13-3.0.1
#    image: wodby/drupal-nginx:6-1.13-3.0.1
#    image: wodby/drupal-nginx:8-1.12-3.0.1
#    image: wodby/drupal-nginx:7-1.12-3.0.1
#    image: wodby/drupal-nginx:6-1.12-3.0.1
    depends_on:
      - php
    environment:
      NGINX_STATIC_CONTENT_OPEN_FILE_CACHE: "off"
      NGINX_ERROR_LOG_LEVEL: debug
      NGINX_BACKEND_HOST: php
      NGINX_SERVER_ROOT: /var/www/html/web
    volumes:
#      - codebase:/var/www/html
# Options for macOS users (https://docker4drupal.readthedocs.io/en/latest/macos)
      - ../:/var/www/html:delegated # User-guided caching
#      - docker-sync:/var/www/html # Docker-sync
    labels:
      - 'traefik.backend=nginx'
      - 'traefik.port=80'
      - 'traefik.frontend.rule=Host:PROJECT_NAME.docker.localhost'

Here you again need to uncomment the correct image to work with. In most cases this will be the first one which is configured for Drupal 8 and is using the latest Nginx version. Also make sure the NGINX_SERVER_ROOT is set to the correct folder where your web application lies. This is most likely the place where index.php exists. Uncomment the correct volume with the same configuration as per the PHP image instructions and also change the PROJECT_NAME for your domain configuration.

Solr

solr:
# wodby/drupal-solr:[DRUPAL_VERSION]-[SOLR_VERSION]-[STABILITY_TAG].
#    image: wodby/drupal-solr:8-6.6-2.2.0
#    image: wodby/drupal-solr:8-6.5-2.2.0
#    image: wodby/drupal-solr:8-6.4-2.2.0
#    image: wodby/drupal-solr:8-6.3-2.2.0
    image: wodby/drupal-solr:8-5.5-2.2.0
#    image: wodby/drupal-solr:7-5.4-2.2.0
    environment:
      SOLR_HEAP: 1024m
    labels:
      - 'traefik.backend=solr'
      - 'traefik.port=8983'
      - 'traefik.frontend.rule=Host:solr.PROJECT_NAME.docker.localhost'

Depending on your project, you might also need a Solr server. Uncomment the following block and also make sure you use the correct image. Note the Drupal and Solr version. This might depend on the project and actual hosting configuration.

results matching ""

    No results matching ""