> For the complete documentation index, see [llms.txt](https://docs.beldex.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.beldex.io/master-nodes/guides/master-node-docker-setup.md).

# Master Node Docker Setup

A guide to setup master node using docker

The easiest and most efficient way to set up a master node is by using Docker. Follow these two simple steps to set up a master node with Docker. We have provided a shell script to handle all the heavy lifting for you.

> Note: This guide assumes some familiarity with the command line and running a Linux server. For a more detailed walkthrough, check out our full Master Node setup guide.

### Step 1 :  Create or Download the shell file

Copy the below code to a shell file `master-node-deploy.sh`&#x20;

```sh
#!/bin/bash
set -euo pipefail

IMAGE_NAME="beldex/beldex-master-node:v2"
CONTAINER_NAME="beldex-mn-node"
SERVICE_NAME="beldex-testnet-storage-server.service"

echo "Starting container..."
# choose the run command you want — simple example (Option A assumes the image runs the node directly)
docker run --network=host --privileged --name "$CONTAINER_NAME" -d "$IMAGE_NAME" || true

# give the daemon a second to settle
sleep 3

# Get container id even if it's exited
CONTAINER_ID=$(docker ps -aq --filter "name=^/${CONTAINER_NAME}$")

if [ -z "$CONTAINER_ID" ]; then
  echo "No container was created with name: $CONTAINER_NAME"
  exit 1
fi

# If it's not running, print logs and exit (helpful for debugging)
STATUS=$(docker inspect -f '{{.State.Status}}' "$CONTAINER_ID")
if [ "$STATUS" != "running" ]; then
  echo "Container $CONTAINER_NAME (ID $CONTAINER_ID) is not running. Status: $STATUS"
  echo "== docker logs =="
  docker logs "$CONTAINER_ID" || true
  echo "== docker inspect =="
  docker inspect "$CONTAINER_ID"
  exit 1
fi

echo "Container is running: $CONTAINER_ID"

# Update script to run inside the container (unchanged)
UPDATE_SCRIPT=$(cat <<'EOF'
IP=$(curl -sS http://api.ipify.org || true)
echo "IP for belnet: $IP"

sed -i -e "s/^master-node-public-ip=.*/master-node-public-ip=$IP/" /etc/beldex/beldex.conf

PRIVATE_IP=$(ip route get 1.2.3.4 | awk '{print $7}')
echo "PRIVATE_IP for belnet: $PRIVATE_IP"

sed -i -e "s/^public-ip=.*/public-ip=$IP/" /var/lib/belnet/router/belnet.ini
sed -i -e "s/^[[:space:]]*inbound=.*/     inbound=$PRIVATE_IP/" /var/lib/belnet/router/belnet.ini
EOF
)

echo "Updating files inside container..."
docker exec "$CONTAINER_ID" bash -lc "$UPDATE_SCRIPT"

echo "Stopping "$SERVICE_NAME"  inside the container..."
docker exec -it "$CONTAINER_ID" systemctl stop "$SERVICE_NAME" || {
  echo "Failed to stop service. Check service name or systemd status inside the container."
  docker exec "$CONTAINER_ID" journalctl -xe --no-pager || true
  exit 1
}

echo "Done."
```

OR

```
wget https://deb.beldex.io/Beldex-projects/master-node-docker/master-node-deploy.sh
```

### Step 2:  Register Master Node

> Make sure the node is fully synced before run this command

#### Check the node status

```
docker exec -it <CONTAINER_ID> beldexd status
```

You should receive an output similar to the screenshot provided. Ensure that the height of your node matches the current network height, which can be verified at [Beldex Explorer](https://explorer.beldex.io). If the heights do not match, allow the node to fully sync, which may take 4-5 hours.

<figure><img src="https://323714467-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Meycnsuwg0Fr0hzLTg6%2Fuploads%2FGsil6rjC49n7AxnSomll%2FScreenshot%202024-08-05%20at%204.58.45%E2%80%AFPM.png?alt=media&amp;token=23758bc0-17d6-49ac-9135-1f585fd0518c" alt=""><figcaption><p>node status</p></figcaption></figure>

#### Prepare for Registration

Once the node is fully synced, run the below command to register the master node

```
docker exec -it <CONTAINER_ID> beldexd prepare_registration
```

After successfully running the command, you will receive an output similar to the screenshot below. To complete the registration, execute the master node command from the output in your wallet.

<figure><img src="https://323714467-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Meycnsuwg0Fr0hzLTg6%2Fuploads%2FJTKqpbYW6OnQTePRQFis%2FScreenshot%202024-08-05%20at%204.58.55%E2%80%AFPM.png?alt=media&amp;token=67aa3c2d-01df-48f9-a380-bf5579684138" alt=""><figcaption><p>master node registration</p></figcaption></figure>

{% hint style="info" %}
You can run all beldexd commands using docker. Run <mark style="color:blue;">`docker exec -it <CONTAINER_ID> beldexd --help`</mark> to get the list of commands
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.beldex.io/master-nodes/guides/master-node-docker-setup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
