This guide outlines the process for deploying a functional single-node Apache Mesos cluster using Docker containers. The architecture consists of four primary components: a ZooKeeper instance for coordination, a Mesos Master for resource management, a Marathon framework for orchestration, and a Mesos Agent to execute tasks.
Prerequisites
Insure a Docker daemon is runing on the host machine. Obtain the IP address of the Docker host, as it is required for inter-container communication.
export DOCKER_HOST_IP=192.168.1.50
Step 1: Deploy ZooKeeper
Start the ZooKeeper container to handle leader election and cluster state coordination.
docker run -d \
--name zk_cluster \
-p 2181:2181 \
-p 2888:2888 \
-p 3888:3888 \
zookeeper:3.6
Step 2: Launch Mesos Master
Run the Mesos Master container. The --net=host flag is recommended to simplify network addressing, ensuring the master advertises the correct host IP.
docker run -d \
--name mesos_master \
--net host \
-e MESOS_HOSTNAME=${DOCKER_HOST_IP} \
-e MESOS_IP=${DOCKER_HOST_IP} \
-e MESOS_ZK=zk://${DOCKER_HOST_IP}:2181/mesos \
-e MESOS_PORT=5050 \
-e MESOS_LOG_DIR=/var/log/mesos \
-e MESOS_QUORUM=1 \
-e MESOS_REGISTRY=in_memory \
-e MESOS_WORK_DIR=/var/lib/mesos \
mesosphere/mesos-master:latest
Step 3: Launch Marathon
Deploy the Marathon framework, which serves as the container orchestration layer for long-running services. It connects to ZooKeeper to discover the Mesos Master.
docker run -d \
--name marathon_service \
-p 8080:8080 \
mesosphere/marathon:latest \
--master zk://${DOCKER_HOST_IP}:2181/mesos \
--zk zk://${DOCKER_HOST_IP}:2181/marathon
Step 4: Launch Mesos Agent
Start the Mesos Agent (formerly slave) to register with the master and offer resources for task execution.
docker run -d \
--name mesos_agent \
--net host \
-e MESOS_HOSTNAME=${DOCKER_HOST_IP} \
-e MESOS_IP=${DOCKER_HOST_IP} \
-e MESOS_MASTER=zk://${DOCKER_HOST_IP}:2181/mesos \
-e MESOS_LOG_DIR=/var/log/mesos \
-e MESOS_CONTAINERIZERS=docker,mesos \
-e MESOS_WORK_DIR=/var/lib/mesos \
mesosphere/mesos-slave:latest
Step 5: Verify Cluster Status
Open a browser and navigate to the Mesos Web UI to confirm the master is active and the agent has registered.
http://${DOCKER_HOST_IP}:5050
Step 6: Deploy a Test Application
Access the Marathon UI to schedule a test task.
http://${DOCKER_HOST_IP}:8080
Create a new application via the UI. Configure the command field to generate output periodically, for instance: while true; do echo "Test Message" >> /tmp/test_output.log; sleep 2; done.
Step 7: Validate Task Execution
Connect to the Mesos Agent container to verify the application is writing to the log file.
docker exec -it mesos_agent /bin/bash
tail -f /tmp/test_output.log