Docker-compose Cluster on Amazon's Linux 2 documentation for the dotCMS Content Management System

This example demonstrates how to set up a scaleable dotCMS docker reference implementation cluster on Amazon's Linux 2 using docker-compose. It is intended as an example and not a perscription for running dotCMS in docker in production environments. The builds dotCMS from the latest master (optional) and uses this the docker-compose file found here:

Finally, this example shows how to start dotCMS as a single node that can be scaled up. This guide is specific for running docker in Amazon's Linux 2 AMI. Other linux distros will have different steps in order to configure their docker environments.

Step 1 Start a Amazon Linux 2 instance

You'll want at least 4 procs and 16GB RAM - I'm using a t3a.xlarge as it is the most economical. Make sure ports 22, 80/443 are open in your security group

After you ssh to your box:

sudo yum update -y
sudo yum install docker git -y

## set elasticsearch virtual memory settings
## Elasticsearch will not start up without this

sudo sysctl -w vm.max_map_count=262144
sudo sysctl -w fs.file-max=100000

## make sure they stick
sudo sh -c "echo 'vm.max_map_count=262144' >> /etc/sysctl.conf"
sudo sh -c "echo 'fs.file-max=100000' >> /etc/sysctl.conf"
sudo sysctl -p

## add ec2-user to docker so you can run them
sudo usermod -a -G docker ec2-user

## edit docker file limits
sudo sh -c "echo \"OPTIONS='--default-ulimit nofile=65536:65536'\" >> /etc/sysconfig/docker"

Here you have to log out and log back in or newgrp to the docker group - it's like su-ing to a group. you only have to do this once.

newgrp docker

## start docker
sudo service docker start

## download and install docker-compose
sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

## set perms
sudo chmod +x /usr/local/bin/docker-compose

#Symlink it to your path
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

# test that it works
docker-compose --version

## make data dir
sudo mkdir -p /data/git
sudo chmod -R 777 /data

## clone dotcms docker repo
cd /data/git
git clone

Optional - run from a Github Branch

If you want to build from a branch or from master, you can build a new dotCMS docker image. If you want to just run the latest released version, you should skip this step.

The -t dotcms/dotcms:latest tags this build as the latest dotcms build on the server.
When you start docker-compose, it uses this tag when spinning up the dotCMS.
If you commit to your branch or want to update to the latest master, you can just run the docker build again, tag the new build as the latest and then restart the dotcms in docker-compose.

## In order to build our custom docker image, you need to be in the directory with the dotCMS Dockerfile
cd docker/images/dotcms/

## Build from MASTER
docker build --pull --no-cache --build-arg BUILD_FROM=COMMIT --build-arg BUILD_ID=origin/master -t dotcms/dotcms:latest .

## OR build rom a branch 
docker build --pull --no-cache --build-arg BUILD_FROM=COMMIT --build-arg BUILD_ID=origin/issue-16470-force-key-gen -t dotcms/dotcms:latest .

Starting docker with docker-compose

Here we cd into the directory with our docker-compose file and start our new dotCMS installation.

## Fire up a single dotCMS instance

cd /data/git/docker/referenceImplementations/02-single_node/

## take a look at the docker-compose.yml
## it defines and controls the whole environment 
vi docker-compose.yml

## this brings up the whole stack, lb, elasticsearch, db and dotcms
docker-compose up -d 

## tail all the logs
docker-compose logs -f

## you can see a list of running docker containers by running
docker ps

## to connect to the database (or any of the containers), run
docker exec -it {{CONTAINER NAME OR ID}} bash

## e.g.

docker exec -it 02-single_node_db_1 bash
## or 
docker exec -it 02-single_node_dotcms_1 bash

## you can bring down dotCMS and leave the database running, for example:
docker-compose scale dotcms=0

## you can copy files to and from the docker images from the main host by
docker cp ./docker-compose.yml 02-single_node_db_1:/tmp/

At this point you should be able to login and upload a license pack. You can also supply a license pack at startup by editing your docker-compose.yml, specificilly, this line

Finally, let's scale up more dotCMS instances

## to scale the dotcms
docker-compose scale dotcms=3

## follow the logs until all the servers are up
docker-compose logs -f

You should be able to login, fire a reindex, get to the network tab and see your cluster. Once you are done, you can stop the environment by running docker-compose down