Setup a Full Monero Stack with Docker

Tags: Monero Docker

In this article, I am going to try to convince you why you should think about running a Monero stack, and if you’re interested, explain how to run one using Docker.

So, why should you do it? Well, a better question to answer first is: what is a Monero stack?

The components of this so-called stack are:

  • Monerod (Monero Node Daemon)
  • P2Pool (Mini)
  • P2Pool Statistics
  • XMRig (Mining Software)

These are all optional components, meaning you can remove any one of these and, with a few adjustments, make it all run well. That said, I recommend you follow the tutorial as closely as possible to ensure it works without hiccups.

Why Should You Do This?

ContainerAdvantages
Monerod- Running a Monero node helps to decentralize the network.
- Provides privacy and security for transactions.
P2Pool- Allows for a decentralized mining pool without relying on third-party pools.
- Increases security and reliability in the Monero network.
- It has no owner, the fees are 0%, and the payout limit is close to 0 XMR.
P2Pool Statistics- Provides real-time statistics and monitoring of your P2Pool setup.
- Helps track performance and health of the P2Pool server on a website.
XMRig- A high-performance mining software for Monero.
- Allows you to mine Monero on your own hardware.

In short, both Monerod and P2Pool are designed to give you, the end user, more privacy. The P2Pool Statistics component provides a bit of a UI since this is all CLI-based. XMRig is the miner—without it, you don’t even need to run the two containers above it.

Minimum Requirements

Now, let’s get on with the fun part: actually running it. The minimum requirements, as of this writing, for this stack are:

  • At least 125 GB for a pruned (smaller) node or 275 GB for a full node.
  • At least 8 GB of RAM (preferably very fast).
  • A decent CPU (better CPU → more hashrate).
  • Docker installed, preferably on a Debian-based distro. How to install it.

With these requirements met, you’re ready to proceed!

Optional 1: Increase Hashrate with Huge Pages Configuration

To potentially increase your hashrate by up to 50%, you can configure huge pages. This step is optional but recommended for optimizing mining performance.

Temporary Huge Pages Reservation

To reserve huge pages temporarily (until the next reboot), run:

sudo sysctl -w vm.nr_hugepages=1280

Permanent Huge Pages Reservation

To make the reservation permanent, add the following line to your system configuration:

sudo bash -c "echo vm.nr_hugepages=1280 >> /etc/sysctl.conf"

After making this change, reboot your system to apply the configuration.

Note: The memory reserved is calculated as the number of pages multiplied by 2048 KB. For example, reserving 1280 huge pages would require approximately 2.5 GB of memory (1280 * 2048 KB = 2,621,440 KB, which is ~2.5 GB).

Optional 2: Forward Ports for Better Connectivity

To improve connectivity and ensure your Monero stack operates optimally, you can forward the following ports on your router:

  • Port 18080: This is used by Monerod for node-to-node communication. Forwarding this port allows other nodes in the Monero network to connect to your node, contributing to network decentralization and improving your node’s connectivity.

  • Port 37888: This is used by P2Pool for decentralized mining pool communication. Forwarding this port allows other miners to connect to your P2Pool instance, enhancing its reliability and reach within the network.

Note: Port forwarding is optional but recommended if you want to maximize the benefits of running a Monero node and P2Pool. Each router’s interface is different, so you’ll need to look up specific instructions for your model.

1. Create a Folder for Your Monero Stack

First, create a directory to store all the necessary files for your Monero stack. Open a terminal and run:

mkdir monero-stack
cd monero-stack

2. Create a docker-compose.yml File

Inside the monero-stack folder, create a docker-compose.yml file. You can use any text editor, such as nano or vim. For example:

nano docker-compose.yml

Copy and paste the following content into the file. Replace the placeholders (<...>) with your specific values in the next step:

# Replace <USER_ID>:<, <GROUP_ID>, <WALLET_ADDRESS>, <WORKER_ID>, and <THREAD_COUNT> before running. 
# Remove the comments in the "command" section of each container.

name: monero_stack
services:
    monerod:
        image: ghcr.io/sethforprivacy/simple-monerod:latest
        container_name: monerod
        user: <USER_ID>:<GROUP_ID> # Replace with your user and group ID
        restart: unless-stopped
        networks:
            backend:
                ipv4_address: 172.19.3.2
        ports:
            - "18089:18089" # RPC port for restricted API
            - "18080:18080" # P2P port for node communication
        volumes:
            - ./monerod:/home/monero/.bitmonero
        command: >
            --out-peers 150
            --in-peers 1024
            --hide-my-port
            --rpc-restricted-bind-ip=0.0.0.0
            --rpc-restricted-bind-port=18089
            --rpc-bind-ip=0.0.0.0
            --confirm-external-bind
            --enable-dns-blocklist
            --no-igd
            --limit-rate-up 2048
            --limit-rate-down 1048576
            --zmq-pub=tcp://0.0.0.0:18083
            --prune-blockchain # Remove if you want to run a full node

    p2pool:
        image: ghcr.io/rodrigomaia06/p2pool-docker:latest
        container_name: p2pool
        privileged: true
        restart: unless-stopped
        networks:
            backend:
                ipv4_address: 172.19.3.3
        depends_on:
            - monerod
        ports:
            - "18333:18333" # Stratum port for miners
            - "37888:37888" # P2Pool mini connection port
        volumes:
            - ./p2pool/:/home/p2pool/.p2pool:rw
            - /dev/hugepages:/dev/hugepages:rw
        command: >
            --host 172.19.3.2
            --local-api
            --data-api /home/p2pool/.p2pool
            --rpc-port 18081
            --no-igd
            --wallet <WALLET_ADDRESS> # Replace with your Monero wallet address
            --p2p 0.0.0.0:37888
            --stratum 0.0.0.0:18333
            --mini

    xmrig:
        image: ghcr.io/rodrigomaia06/xmrig-0donation:latest
        container_name: xmrig
        privileged: true
        user: root
        restart: unless-stopped
        cap_add:
            - SYS_ADMIN
            - SYS_RAWIO
        devices:
            - /dev/cpu
            - /dev/mem
        networks:
            backend:
                ipv4_address: 172.19.3.4
        volumes:
            - /lib/modules:/lib/modules
        command: >
            --api-worker-id=<WORKER_ID> # Replace with a unique worker ID
            -o 172.19.3.3:18333
            -k
            --cpu-priority=2 # Replace with the priority (0 lowest, 2 normal to 5 highest)
            --threads <THREAD_COUNT> # Replace with the number of threads to use for mining

    p2pool-statistics:
        image: ghcr.io/rodrigomaia06/p2pool-docker-statistics:latest
        container_name: p2pool-statistics
        ports:
            - "8000:80" # Web interface for P2Pool statistics
        networks:
            backend:
                ipv4_address: 172.19.3.5
        volumes:
            - ./p2pool:/data:ro # Mount P2Pool data directory as read-only
        depends_on:
            - p2pool
        restart: unless-stopped

networks:
    backend:
        driver: bridge
        ipam:
         config:
             - subnet: 172.19.3.0/24

3. Replace Placeholders

Before starting the stack, replace the following placeholders in the docker-compose.yml file:

  • <USER_ID> and <GROUP_ID>: Use the id command in your terminal to find your user and group IDs.
  • <WALLET_ADDRESS>: Enter your Monero wallet address.
  • <WORKER_ID>: Provide a unique identifier for your mining worker.
  • <THREAD_COUNT>: Set the number of CPU threads to use for mining.

4. Start the Stack

Run the following command to start all the containers:

docker-compose up -d

5. Verify the Setup

  • Access the Monero node’s restricted RPC API at [MACHINE'S IP]:18089. This port is used for interacting with the Monero node via a restricted API, allowing you to query blockchain data securely. How to use with a wallet.
  • Allow extra miners to connect to P2Pool via the Stratum port at [MACHINE'S IP]:18333. This port enables miners to join your P2Pool instance and contribute to decentralized mining.
  • Check P2Pool statistics at http://[MACHINE'S IP]:8000. This port serves the web interface for monitoring your P2Pool setup, providing real-time statistics and performance metrics.

Folder Structure Notes

After setting up the Monero stack, your folder structure should look like this:

monero-stack/
├── docker-compose.yml  # The main configuration file for Docker Compose
├── monerod/            # Directory to store Monero node data
├── p2pool/             # Directory to store P2Pool data
  • docker-compose.yml: Contains the configuration for all the services in your stack.
  • monerod/: Stores the blockchain data and configuration for the Monero node.
  • p2pool/: Stores the data and configuration for the P2Pool service.

Ensure these directories have the correct permissions to allow the containers to read and write data as needed.