如何在Docker中搭建同一主机的多节点MarkLogic集群
Got it, let's walk through how to spin up a MarkLogic cluster with multiple nodes on a single machine using Docker. I'll break this into clear, actionable steps so you can follow along easily.
1. Prepare the MarkLogic Docker Image
First, pull the official MarkLogic image from Docker Hub. It's best to specify a stable version (like 11.0.0) instead of using latest to avoid unexpected changes:
docker pull marklogicdb/marklogic-server:11.0.0
2. Create a Custom Docker Network
Multiple MarkLogic nodes need to communicate with each other. A custom bridge network lets containers resolve each other by name, which simplifies cluster setup:
docker network create ml-cluster-network
3. Start the First (Seed) Node
This node will be the foundation of your cluster. We'll map unique host ports, mount a persistent volume for data, and attach it to our custom network:
docker run -d \ --name ml-node1 \ --network ml-cluster-network \ --memory 4g --cpus 2 \ # Allocate sufficient resources (adjust based on your machine) -p 8000:8000 -p 8001:8001 -p 8002:8002 -p 8003:8003 -p 8004:8004 -p 8005:8005 -p 8006:8006 \ -v ml-node1-data:/var/opt/MarkLogic \ marklogicdb/marklogic-server:11.0.0
Wait 5-10 minutes for the node to initialize. Then open http://localhost:8001 in your browser, set an admin username/password, and complete the initial setup wizard.
4. Start Additional Nodes
For each extra node, use a unique container name, host port range, and persistent volume. Let's add ml-node2 as an example:
docker run -d \ --name ml-node2 \ --network ml-cluster-network \ --memory 4g --cpus 2 \ -p 8100:8000 -p 8101:8001 -p 8102:8002 -p 8103:8003 -p 8104:8004 -p 8105:8005 -p 8106:8006 \ -v ml-node2-data:/var/opt/MarkLogic \ marklogicdb/marklogic-server:11.0.0
Again, wait for initialization, then open http://localhost:8101 and set the same admin username/password as the seed node. This is critical for cluster joining.
5. Add the New Node to the Cluster
You can do this via the web UI or REST API. Here's both methods:
Option 1: Web UI (ml-node1's Admin Console)
- Go to
http://localhost:8001and log in. - Navigate to Cluster > Hosts in the left sidebar.
- Click Add Host.
- Enter
ml-node2as the Host Name (this is the container name, resolvable via our custom network), set Connect Port to8001, and select theDefaultgroup. - Click OK and wait for the cluster to sync (this may take a few minutes).
Option 2: REST API (Automated)
Run this curl command from your host machine (replace your-admin-password with your actual password):
curl -X POST -u admin:your-admin-password \ -H "Content-Type: application/json" \ http://localhost:8001/manage/v2/hosts \ -d '{ "host-name": "ml-node2", "group": "Default", "connect-port": 8001 }'
6. Verify Cluster Status
To confirm the cluster is working:
- Check the Cluster > Hosts page in ml-node1's admin console—both nodes should show as
online. - Or use the REST API to fetch host status:
curl -u admin:your-admin-password http://localhost:8001/manage/v2/hosts?format=json
7. Add More Nodes (Optional)
Repeat steps 4 and 5 for additional nodes (e.g., ml-node3 with port range 8200-8206 and volume ml-node3-data).
Key Notes to Remember
- Persistent Volumes: Each node must have its own dedicated volume—never share volumes between nodes, as this will cause data corruption.
- Resource Allocation: MarkLogic is resource-heavy. Each node needs at least 2GB of RAM (4GB recommended) and 2 CPU cores. Adjust the
--memoryand--cpusflags based on your machine's capacity. - Port Conflicts: Ensure host port ranges are unique for each node (e.g., 8000-8006 for node1, 8100-8106 for node2) to avoid binding errors.
- Admin Credentials: All nodes must use identical admin credentials to join the cluster.
内容的提问来源于stack exchange,提问作者bosari

