Docker Compose
Docker Compose is a tool for defining and running multi-container Docker applications. In Appway's context, this allows running multiple nodes.
Prerequisites
Ensure that the FNZ Studio Docker image contains a hazelcast.xml configuration file that has Multicast enabled. This allows multiple cluster nodes to connect to each other.
Resources
To run Appway using Docker Compose:
- Create a configuration file called
docker-compose.yamlwhere the Appway instances are configured. - Configure a Load Balancer that serves as the main entry point when accessing Appway. The Load Balancer forwards the requests to the Appway nodes.
In the following example, a Nginx server is configured:
# file name: nginx.conf
worker_processes 1;
events { worker_connections 1024; }
http {
access_log off;
sendfile on;
upstream app_servers {
# sticky sessions
ip_hash;
server appway_appway_1:8080;
server appway_appway_2:8080;
}
server {
listen 80;
client_body_buffer_size 50M;
client_max_body_size 1000M;
proxy_read_timeout "1800";
proxy_connect_timeout "600";
proxy_send_timeout "600";
location / {
proxy_pass http://app_servers;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
}
The following example of the docker-compose.yaml file shows a possible configuration for an Appway cluster:
Note: For simplicity, the Cluster Storage is configured to use the filesystem and the folder is mounted as a Docker volume; but this can be customized and replaced by any Cluster Storage extension (e.g. Azure Hazelcast Store, AWS Hazelcast Store, Cassandra Hazelcast Store, Relational Db Hazelcast Store).
# file name: docker-compose.yaml
version: '3'
services:
appway:
image: ${APPWAY_IMAGE}
expose:
- "8080"
environment:
- JAVA_OPTS=-Xmx2g -Duser.language=en -Duser.country=US -Duser.timezone=Europe/Zurich -Dfile.encoding=UTF8
volumes:
- ${CLUSTER_DIRECTORY}:/appway/data-home/cluster
- ${LICENSE_FILE_PATH}:/appway/data-home/conf/license.properties
restart: unless-stopped
nginx:
image: nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
ports:
- "8080:80"
Run Appway
Create the following script to run Appway. When executed, the script requests the Cluster Storage location and the license file location as parameters.
# file name: run-appway.sh
clusterStorageDirectoryPath=$1
licenseFilePath=$2
appwayImage=${3:-appway}
numNodes=${4:-2}
if [[ ! -d "${clusterStorageDirectoryPath}" || ! -f ${licenseFilePath} ]]; then
echo "Usage: $0 <clusterStorageDirectoryPath> <licenseFilePath>"
exit 1
fi
export APPWAY_IMAGE=${appwayImage}
export CLUSTER_DIRECTORY=${clusterStorageDirectoryPath}
export LICENSE_FILE_PATH=${licenseFilePath}
export COMPOSE_PROJECT_NAME=appway
docker-compose up --scale appway=${numNodes}
After saving the script, you can execute it in the following way (make sure you pass valid Cluster Storage and license file paths):
./run-appway.sh /tmp/appway/cluster /tmp/appway/license.properties
You can use the docker-compose scale command to scale the Appway cluster up or down.
Shutdown Appway
To shut down the Appway cluster, you can use a script similar to this example:
# file name: stop-appway.sh
export COMPOSE_PROJECT_NAME=appway
docker-compose down -t 60
Shutdown and Scaling without Data Loss
Make sure that you use the timeout parameter of the docker-compose command. Set a sufficiently large value for this timeout to ensure that the Appway nodes have enough time to shut down correctly, otherwise data loss can occur.
We recommend setting a timeout of 60s to begin with, but it is very important to test how long your Solution actually takes to shut down, and increase the timeout accordingly if your Solution needs more time to stop.