# Run in Docker

Prequirements: This guide assumes your running a Linux based operating system and have Docker already installed.

## Docker image details

Liberland's node docker image is hosted on GitHub Container Registry: [ghcr.io/liberland/blockchain-node](https://github.com/orgs/liberland/packages/container/package/blockchain-node). It's build automatically from public [Dockerfile](https://github.com/liberland/liberland_substrate/blob/main/Dockerfile-prebuilt). Configuration:

* Node binary is stored at `/node`
* Exposed ports: `30333`, `9944`.
* Runs as unpriviledged user with UID 1000

## Usage examples

### Minimal Bastiat (testnet) node with persistent data

To make sure your node's data is persistant, mount a host directory as a volume using `-v` argument:

```bash
$ mkdir $HOME/liberland_data
$ sudo chown 1000:1000 $HOME/liberland_data
$ docker run -it --rm -v $HOME/liberland_data:/data ghcr.io/liberland/blockchain-node:latest -d /data --chain bastiat
```

### Using custom chain spec

To use custom chain spec, you must mount it into the container:

```bash
$ mkdir $HOME/liberland_data
$ sudo chown 1000:1000 $HOME/liberland_data
$ docker run -it --rm -v $HOME/liberland_data:/data -v $HOME/custom_chain_spec.raw.json:/custom_chain_spec.raw.json ghcr.io/liberland/blockchain-node:latest -d /data --chain /custom_chain_spec.raw.json
```

### Accessing your node locally via Polkadot.js Apps

To be able to access your node locally via Polkadot.js Apps, pass `--network=host` argument so that RPC port is accessible:

```bash
$ mkdir $HOME/liberland_data
$ sudo chown 1000:1000 $HOME/liberland_data
$ docker run -it --rm --network=host -v $HOME/liberland_data:/data ghcr.io/liberland/blockchain-node:latest -d /data --chain bastiat
```

You'll now be able to access your node via <https://polkadotjs.blockchain.liberland.org/?rpc=ws://localhost:9944>.

### Complete example of running a validator on mainnet

This example:

* passes `-v $HOME/liberland_data:/data` to make data persistent on the host
* passes `--network=host` to make RPC accessible locally and P2P accessible on all interfaces
* passes `-d` to run in background
* passes `--restart always` to automatically restart node on reboot / crash
* uses mainnet chain spec
* passes `--validator` option to node to enable acting as validator

```bash
$ mkdir $HOME/liberland_data
$ sudo chown 1000:1000 $HOME/liberland_data
$ docker run --name liberland -d --network=host --restart always -v $HOME/liberland_data:/data ghcr.io/liberland/blockchain-node:latest -d /data --chain mainnet --validator
```

You can:

* monitor this instance with `docker ps -a`
* see its logs with `docker logs liberland`
* stop with `docker stop liberland` - note that it will restart automatically on reboot / Docker restart
* restart with `docker restart liberland`
* remove with `docker rm liberland`

#### Generate session keys

See [regenerate session keys](https://github.com/liberland/docs/blob/master/blockchain/for-validators-nominators-and-stakers/regenerate_session_keys.md) document.

With an instance running like this you may now follow the [Run a validator](/blockchain/for-validators-nominators-and-stakers/run-a-validator.md#wait-for-your-node-to-sync) starting with **Wait for your node to sync** section.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.liberland.org/blockchain/for-developers-and-testers/docker.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
