2 min read

Categories

Tags

I have recently started testing and using docker4drupal. (I also use DrupalVM and vagrant; but that’s another post.) I setup to be quick and easy.

Setup

You will need:

Docker Compose Spacely Sprockets (new site)

~/Sites/spacely-sprokets/docker-compose.yml

version: "2"

services:
  mariadb:
    image: wodby/mariadb:10.1-2.3.3
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: drupal
      MYSQL_USER: drupal
      MYSQL_PASSWORD: drupal

  php:
# 1. Images with vanilla Drupal – wodby/drupal:[DRUPAL_VERSION]-[PHP_VERSION]-[STABILITY_TAG].
    image: wodby/drupal:8-7.1-2.4.4
    environment:
      PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025
      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         # This is needed to respect remote.host setting below
      # PHP_XDEBUG_REMOTE_HOST: "10.254.254.254"  # You will also need to 'sudo ifconfig lo0 alias 10.254.254.254'
    volumes:
       - spacely-sprokets-sync:/var/www/html # Docker-sync

  nginx:
# wodby/drupal-nginx:[DRUPAL_VERSION]-[NGINX_VERSION]-[STABILITY_TAG].
    image: wodby/drupal-nginx:8-1.13-2.4.2
    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:
       - spacely-sprokets-sync:/var/www/html # Docker-sync
    labels:
      - 'traefik.backend=nginx'
      - 'traefik.port=80'
      - 'traefik.frontend.rule=Host:spacely-sprokets.docker.localhost'

   mailhog:
    image: mailhog/mailhog
    labels:
      - 'traefik.backend=mailhog'
      - 'traefik.port=8025'
      - 'traefik.frontend.rule=Host:mailhog.spacely-sprokets.docker.localhost'

volumes:
# Docker-sync for macOS users
   spacely-sprokets-sync:
     external: true

Docker Sync Spacely Sprockets

~/Sites/spacely-sprokets/docker-sync.yml

version: “2”

syncs:
  spacely-sprokets-sync:
src: ‘./‘
sync_userid: ‘82'
sync_excludes: [‘.gitignore', ‘.git/‘, ‘.idea/‘]

Docker Cogswell Cogs (existing code)

~/Sites/cogswell-cogs/docker-compose.yml

version: "2"

services:
  mariadb:
    image: wodby/mariadb:10.1-2.3.3
    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.

  php:
# 2. Images without Drupal – wodby/drupal-php:[PHP_VERSION]-[STABILITY_TAG].
     image: wodby/drupal-php:5.6-2.4.3
    environment:
      PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025
      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         # This is needed to respect remote.host setting below
      # PHP_XDEBUG_REMOTE_HOST: "10.254.254.254"  # You will also need to 'sudo ifconfig lo0 alias 10.254.254.254'
    volumes:
       - cogswell-cogs-sync:/var/www/html # Docker-sync

   apache:
     image: wodby/drupal-apache:2.4-1.0.2
    depends_on:
      - php
     environment:
       APACHE_LOG_LEVEL: debug
       APACHE_BACKEND_HOST: php
       APACHE_SERVER_ROOT: /var/www/html/www
     volumes:
    - cogswell-cogs-sync-sync:/var/www/html # Docker-sync
     labels:
       - 'traefik.backend=apache'
       - 'traefik.port=80'
       - 'traefik.frontend.rule=Host:drupal.docker.localhost'

  mailhog:
    image: mailhog/mailhog
    labels:
      - 'traefik.backend=mailhog'
      - 'traefik.port=8025'
      - 'traefik.frontend.rule=Host:mailhog.drupal.docker.localhost'

volumes:
 # Docker-sync for macOS users
   cogswell-cogs-sync:
     external: true

Docker Sync Cogswell Cogs

~/Sites/cogswell-cogs/docker-sync.yml

version: “2”

syncs:
  cogswell-cogs-sync:
src: ‘./‘
sync_userid: ‘82'
sync_excludes: [‘.gitignore', ‘.git/‘, ‘.idea/‘]

Traefik.yml

~/Sites/traefik.yml

version: ‘2'

services:
  traefik:
    image: traefik
    restart: unless-stopped
    command: -c /dev/null –web –docker –logLevel=DEBUG
    networks:
        - spacelysprokets
        - cogswellcogs
        - sites
     ports:
        - ‘80:80'
        - ‘8080:8080'
   volumes:
       - /var/run/docker.sock:/var/run/docker.sock
  portainer:
        image: portainer/portainer
        command: '--no-auth'
        volumes:
            - '/var/run/docker.sock:/var/run/docker.sock'
        labels:
            - traefik.backend=portainer
            - traefik.port=9000
            - 'traefik.frontend.rule=Host:portainer.docker.localhost'
networks:
  spacelysprokets:
    external:
      name: spacelysprokets_default
  cogswellcogs:
    external:
      name: cogswellcogs_default
  sites:
    external:
      name: sites_default

Commands

Start Cogswell Cogs

cd ~/Sites/cogswell-cogs
docker-sync-stack start

Start Spacely Sprokets

cd ~/Sites/spacely-sprokets
docker-sync-stack start

Start traefik and portainer.

cd ~/Sites
docker-compose -f traefik.yml up -d

Shell access to the site

cd ~/Sites/cogswell-cogs
docker-compose exec --user=82 php sh

Stop docker

cd ~/Sites/cogswell-cogs
docker-compose -f ../traefik.yml stop
docker-compose stop
docker-sync stop