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 inside user-docker-compose directory named docker-compose-elastic-search.yml (All yml/yaml files inside this directory will be used to add custom containers). Populate the file with the following contents:

services:

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.14.3
    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:
      example.com:

volumes:
  examplecom_elasticsearch:
    external: true

networks:
  example.com:
    name: ${VIRTUAL_HOST}

Note: Please update example.com in the above file with your site name. CPU and memory limit should be adjusted accordingly.

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.