Skip to content

Run a Node on Moonbeam Using Docker

Full Node Moonbeam Banner

Introduction

Running a full node on a Moonbeam-based network allows you to connect to the network, sync with a bootnode, obtain local access to RPC endpoints, author blocks on the parachain, and more.

Installation Instructions

A Moonbeam node can be spun up quickly using Docker. For more information on installing Docker, please visit this page. At the time of writing, the Docker version used was 19.03.6. When connecting to Moonriver on Kusama, it will take a few days to completely sync the embedded Kusama relay chain. Make sure that your system meets the requirements.

Create a local directory to store the chain data:

mkdir /var/lib/alphanet-data
mkdir /var/lib/moonriver-data

Next, make sure you set the ownership and permissions accordingly for the local directory that stores the chain data. In this case, set the necessary permissions either for a specific or current user (replace DOCKER_USER for the actual user that will run the docker command):

# chown to a specific user
chown DOCKER_USER /var/lib/alphanet-data

# chown to current user
sudo chown -R $(id -u):$(id -g) /var/lib/alphanet-data
# chown to a specific user
chown DOCKER_USER /var/lib/moonriver-data

# chown to current user
sudo chown -R $(id -u):$(id -g) /var/lib/moonriver-data

Now, execute the docker run command. If you are setting up a collator node, make sure to follow the code snippets for "Collator". Note that you have to replace YOUR-NODE-NAME in two different places.

Full Node

docker run --network="host" -v "/var/lib/alphanet-data:/data" \
-u $(id -u ${USER}):$(id -g ${USER}) \
purestake/moonbeam:v0.15.1 \
--base-path=/data \
--chain alphanet \
--name="YOUR-NODE-NAME" \
--execution wasm \
--wasm-execution compiled \
--pruning archive \
--state-cache-size 1 \
-- \
--pruning archive \
--name="YOUR-NODE-NAME (Embedded Relay)"
docker run --network="host" -v "/var/lib/moonriver-data:/data" \
-u $(id -u ${USER}):$(id -g ${USER}) \
purestake/moonbeam:v0.15.1 \
--base-path=/data \
--chain moonriver \
--name="YOUR-NODE-NAME" \
--execution wasm \
--wasm-execution compiled \
--pruning archive \
--state-cache-size 1 \
-- \
--pruning archive \
--name="YOUR-NODE-NAME (Embedded Relay)"

Collator

docker run --network="host" -v "/var/lib/alphanet-data:/data" \
-u $(id -u ${USER}):$(id -g ${USER}) \
purestake/moonbeam:v0.15.1 \
--base-path=/data \
--chain alphanet \
--name="YOUR-NODE-NAME" \
--validator \
--execution wasm \
--wasm-execution compiled \
--pruning archive \
--state-cache-size 1 \
-- \
--pruning archive \
--name="YOUR-NODE-NAME (Embedded Relay)"
docker run --network="host" -v "/var/lib/moonriver-data:/data" \
-u $(id -u ${USER}):$(id -g ${USER}) \
purestake/moonbeam:v0.15.1 \
--base-path=/data \
--chain moonriver \
--name="YOUR-NODE-NAME" \
--validator \
--execution wasm \
--wasm-execution compiled \
--pruning archive \
--state-cache-size 1 \
-- \
--pruning archive \
--name="YOUR-NODE-NAME (Embedded Relay)"

If you're using MacOS, you can find all the code snippets here.

Once Docker pulls the necessary images, your full Moonbeam (or Moonriver) node will start, displaying lots of information, such as the chain specification, node name, role, genesis state, and more:

Full Node Starting

Note

If you want to run an RPC endpoint, to connect polkadot.js.org, or to run your own application, use the flags --unsafe-rpc-external and/or --unsafe-ws-external to run the full node with external access to the RPC ports. More details are available by running moonbeam --help.

Note

You can specify a custom Prometheus port with the --prometheus-port XXXX flag (replacing XXXX with the actual port number). This is possible for both the parachain and embedded relay chain.

docker run -p 30334:30334 -p 30333:30333 -p 9933:9933 -p 9944:9944 #rest of code goes here

During the syncing process, you will see messages from both the embedded relay chain and the parachain (without a tag). These messages display a target block (live network state) and a best block (local node synced state).

Full Node Starting

Note

It will take a few days to completely sync the embedded Kusama relay chain. Make sure that your system meets the requirements.

If you followed the installation instructions for Moonbase Alpha, once synced, you will have a node of the Moonbase Alpha TestNet running locally!

If you followed the installation instructions for Moonriver, once synced, you will be connected to peers and see blocks being produced on the Moonriver network! Note that in this case you need to also sync to the Kusama relay chain, which might take a few days.

Update the Client

As Moonbeam development continues, it will sometimes be necessary to upgrade your node software. Node operators will be notified on our Discord channel when upgrades are available and whether they are necessary (some client upgrades are optional). The upgrade process is straightforward and is the same for a full node or collator.

  1. Stop the docker container:

    sudo docker stop `CONTAINER_ID`
    
  2. Get the latest version of Moonbeam from the Moonbeam GitHub Release page

  3. Use the latest version to spin up your node. To do so, replace the version in the Full Node or Collator command with the latest and run it

Once your node is running again, you should see logs in your terminal.

Purge Your Node

If you need a fresh instance of your Moonbeam node, you can purge your node by removing the associated data directory.

You'll first need to stop the Docker container:

  sudo docker stop `CONTAINER_ID`

If you did not use the -v flag to specify a local directory for storing your chain data when you spun up your node, then the data folder is related to the Docker container itself. Therefore, removing the Docker container will remove the chain data.

If you did spin up your node with the -v flag, you will need to purge the specified directory. For example, for the suggested data directly, you can run the following command to purge your parachain and relay chain data:

sudo rm -rf /var/lib/alphanet-data/*
sudo rm -rf /var/lib/moonriver-data/*

To only remove the parachain data for a specific chain, you can run:

sudo rm -rf /var/lib/alphanet-data/chains/*
sudo rm -rf /var/lib/moonriver-data/chains/*

Similarly, to only remove the relay chain data, you can run:

sudo rm -rf /var/lib/alphanet-data/polkadot/*
sudo rm -rf /var/lib/moonriver-data/polkadot/*

Now that your chain data has been purged, you can start a new node with a fresh data directory. You can install the newest version by repeating the Installation Instructions. Make sure you are using the latest tag available, which you can find on the Moonbeam GitHub Release page.

Note

On an as-needed basis, Moonbase Alpha might be purged and reset. In these instances, you will need to purge both the parachain data and the relay chain data. If a purge is required, node operators will be notified in advance (via our Discord channel).