Architecture > Advanced Setup
Running 3forge with Docker
This page will provide instructions for deploying and managing multiple, isolated instances of AMI using Docker.
Requirements
- Docker
- WSL (if running on Windows)
- AMI
- Java version 1.8
Note
If using Windows, you will need to have WSL running to interface with Docker. Any command line prompts should be done within WSL.
Setup
-
Create a file called Dockerfile in root directory of your AMI installation folder (e.g: C:\Program Files\ami). Paste the following into your file:
| # Base image with Java 8
FROM openjdk:8-jdk
# Create app directory
WORKDIR /opt/ami
# Copy everything from current folder (assumed to be mounted)
COPY . .
# Make the start script executable
RUN chmod +x amione/scripts/start.sh
# Set environment variables
ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
ENV PATH="$JAVA_HOME/bin:$PATH"
# Expose relevant ports (adjust if needed)
EXPOSE 33332
# Default command: run the AMI start script
CMD /["bash", "amione/scripts/start.sh", "1"]
|
Note
Please ensure that the Dockerfile has no extension. It should be a plain file rather than a .txt file.
-
Navigate to the directory of the AMI installation folder (e.g: C:\Program Files\ami) where the Dockerfile is, and in your command line interface run:
| docker build -t ami-image .
|
This will build an image of AMI named "ami-image" which Docker containers can then then be run on.
-
Now navigate to the /amione/scripts directory and find the start.sh file. Append the following to the very top of the document:
| BASE_NAME="ami-instance"
BASE_HOST_PORT=33332
CONTAINER_PORT=33332
IMAGE_NAME="ami-image"
NUM_CONTAINERS=${1:-1}
PERSIST_DIRS=(
"config"
"data"
"hdb"
"persist"
"lib"
"web_resources"
"scripts"
)
echo "Starting to launch $NUM_CONTAINERS containers..."
for ((i=0; i<NUM_CONTAINERS; i++))
do
UNIQUE_HOSTNAME="${BASE_NAME}-${i}"
HOST_PORT=$((BASE_HOST_PORT + i))
VOLUME_FLAGS=""
for dir in "${PERSIST_DIRS[@]}"; do
VOLUME_NAME="${UNIQUE_HOSTNAME}-${dir}-dir"
APP_PATH="/ami/amione/${dir}"
VOLUME_FLAGS+=" -v $VOLUME_NAME:$APP_PATH"
done
echo "Launching container: $UNIQUE_HOSTNAME on port $HOST_PORT with volume $VOLUME_NAME"
docker run -d \
--hostname "$UNIQUE_HOSTNAME" \
--name "$UNIQUE_HOSTNAME" \
-p "${HOST_PORT}:${CONTAINER_PORT}" \
$VOLUME_FLAGS \
"$IMAGE_NAME"
done
echo ""
echo "--- Active Containers ---"
docker ps --filter "name=$BASE_NAME"
echo ""
echo "--- Created Volumes ---"
docker volume ls --filter "name=${BASE_NAME}-.*-data"
|
The top level configurations are as follows:
BASE_NAME: The prefix for all container names and hostnames (e.g: ami-instance).
IMAGE_NAME: The name of the Docker image to use (ami-image).
NUM_CONTAINERS: The total number of container instances to launch.
PERSIST_DIRS: The directories to persist (uniquely named volumes).
Ports may have to be individually configured to avoid conflicts. Save your file after editing.
-
In your command line, run:
| ./start.sh # Single container
./start.sh 3 # Multiple containers. (e.g. 3)
|
At this point, Docker should run the requested amount of containers.