Skip to content

Playing with Docker and Crypto

In recent years, cryptocurrency mining has become an increasingly popular way for individuals to earn passive income. While mining can be profitable, it’s important to note that the industry is highly competitive and mining revenues are highly variable. In fact, many people who start mining cryptocurrencies end up losing money due to the high cost of hardware, electricity, and other expenses.

That being said, mining can still be an interesting and educational experience, especially for those interested in the technical aspects of cryptocurrencies. In this blog post, we will focus on building a Docker container for Monero mining using the Xmrig miner. Monero is known for its CPU and GPU-friendly algorithm, making it an accessible choice for beginner miners.

This was also an exercise for me to see if AI-assisted coding tools to help speed up the process of building our Docker container.

We’ll explore how to create a more updated version of the Xmrig Docker container than what’s available on Docker Hub, allowing us to take advantage of the latest features and security patches.

How to Build a Docker Container for Xmrig

Xmrig is a popular open-source cryptocurrency miner that allows users to mine a variety of cryptocurrencies using their CPU or GPU. In this tutorial, we will walk through the steps to build a Docker container for Xmrig.

Requirements:

  • Docker installed on your machine
  • Basic knowledge of Docker and command line interface

Step 1: Create a Dockerfile The first step is to create a Dockerfile, which is a text file that contains the instructions for building a Docker image. Here’s an example Dockerfile for building Xmrig:

FROM alpine:latest

RUN apk add --no-cache git build-base cmake libuv-dev openssl-dev hwloc-dev && \
    git clone https://github.com/xmrig/xmrig.git && \
    mkdir xmrig/build && \
    cd xmrig/build && \
    cmake .. && \
    make -j$(nproc) && \
    apk del git build-base cmake && \
    rm -rf /var/cache/apk/*

# Copy config.json to /xmrig/build
# COPY config.json /xmrig/build/

WORKDIR /xmrig/build

ENTRYPOINT ["./xmrig"]

Step 2: Build the Docker image Once you have created the Dockerfile, you can build the Docker image by running the following command in the directory where the Dockerfile is located:

docker build -t xmrig .

This command will build the Docker image with the tag “xmrig”.

Step 3: Run the Docker container After the Docker image has been built, you can run the container using the following command:

docker run -it xmrig

This will start the Xmrig miner inside the Docker container

Step 4: Customize the Xmrig configuration If you want to customize the Xmrig configuration, you can do so by creating a new config.json file and passing it to the Docker container using the -v command line option. Here’s an example config.json file:

You will want to change URL, payment token and process id to your preferred information.

{
    "autosave": true,
    "cpu": true,
    "opencl": false,
    "cuda": false,
    "pools": [
        {
            "url": "pool.supportxmr.com:443",
            "user": "payment token",
            "pass": "process id",
            "keepalive": true,
            "tls": true
        }
    ]
}

To pass this configuration file to the Docker container, you can run the following command:

docker run -it -v /path/to/config.json:/xmrig/build/config.json xmrig

You should start to see output like the following.

Pushing your image to Docker Hub

Get a Docker Hub account if you don’t already have one

Make sure you’re logged in to Docker Hub on your local machine. Run the following command in your terminal, replacing your-docker-username with your actual Docker Hub username

docker login --username your-docker-username

Once you’re logged in, tag your local Docker image with your Docker Hub username and the name of the repository you want to push to. For example

docker tag my-xmrig-image your-docker-username/xmrig

Now you can push your tagged Docker image to Docker Hub using the following command

docker push your-docker-username/xmrig

Once the push is complete, you can check that your image is available on Docker Hub by visiting the following URL in your web browser

https://hub.docker.com/r/your-docker-username/xmrig

Here are the codebase and images:
https://github.com/jmgress/dockerxmrig
https://hub.docker.com/r/mantishand/xmrig

Published inDevOpsTampa Bay DevOps

Be First to Comment

Leave a Reply