Custom Docker Compose Setup Guide

In version 4.6.0 of EasyEngine, we extended the Custom Docker Compose we previously introduced in version 4.2.0. Custom Docker compose give you the power to add extra services to your EasyEngine site. In this guide, we will look at the steps to create your own Docker-Compose and extend the EasyEngine site.

Adding a new service to the site

1. Create a directory named user-docker-compose under /opt/easyengine/sites/example.com/.

From this release onward, EasyEngine will automatically pick up all docker-compose files under user-docker-compose the directory inside /opt/easyengine/sites/example.com/

2. Let’s start with adding Elastic Search service to our site.

Create a file under user-docker-compose a directory named docker-compose-elastic-search.yml. And, populate it with the following:

version: '3.5'

services:

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.2.1
    restart: always
    expose:
      - "9200"
      - "9300"
    volumes:
      - examplecom_elasticsearch:/usr/share/elasticsearch/data
    environment:
      - discovery.type="single-node"
      - xpack.security.enabled=false
      - xpack.security.http.ssl.enabled=false
    deploy:
      resources:
        limits:
          cpus: 2.0
          memory: 2048M
    networks:
      site-network:

volumes:
  examplecom_elasticsearch:
    external: true

networks:
  site-network:
    name: ${VIRTUAL_HOST}

3. As we have added a Docker volume in the above command, we have to create the volume.

docker volume create --name=examplecom_elasticsearch

4. Enable the site

ee site enable --force

5. Time to test the connection

ee shell example.com --command="curl examplecom_elasticsearch_1:9200"

In the above command examplecom_elasticsearch_1 is the name of the Elastic Search container. You can change the name by adding container_name property in the docker-compose file.

To find the name of your Elastic Search container you can also use docker container ls command.

Customizing the existing services

Every EasyEngine site has 4 basic services – Nginx, PHP, Mailhog, and Postfix. In case you want to update one of the services with your custom Docker image you can use a simple docker-compose like below

version: '3.5'

services:

  php:
    image: easyengine/ee-php-node:v0.0.1

Run ee site enable --force and, you’ll have the EasyEngine PHP docker container replaced with your own one.

Command Overview

Enable or Disable a custom service

ee site [enable|disable] <site_name> --custom-compose=<custom_compose_file_name>
ee site [enable|disable] example.com --custom-compose=docker-compose-elastic-search.yml

Restart a custom service

ee site restart example.com --custom-compose=docker-compose-elastic-search.yml

Using enable/disable/restart command without --custom-compose will restart all the services including custom for the specified site.