How do I run XMRig in a Docker container?
You can run XMRig in Docker by building a container image, then starting it with your mining pool address and Monero wallet address. Start with a small CPU limit and ordinary memory settings; Docker makes deployment easier, but it does not automatically improve mining speed.
1. Prepare your computer
XMRig is mining software that uses your processor, or CPU, to work on Monero’s mining calculations. Docker runs that software in an isolated environment called a container.
You need:
- Docker installed and running.
- A computer you own or have clear permission to use.
- Your public Monero wallet address.
- A mining pool’s server address and connection port. A pool combines miners’ work and shares payouts.
Linux is usually the simplest option. Docker Desktop on Windows or macOS runs Linux containers inside a virtual machine, which can add overhead and complicate performance tuning.
This setup mines through XMRig, not through your browser.
2. Build an image from XMRig’s source
Avoid anonymous “ready-to-mine” images. They may contain modified software or send rewards to someone else.
Create an empty folder and save this as Dockerfile:
FROM ubuntu:24.04
ARG XMRIG_VERSION
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates git build-essential cmake \
libuv1-dev libssl-dev libhwloc-dev \
&& rm -rf /var/lib/apt/lists/*
RUN test -n "$XMRIG_VERSION" \
&& git clone --depth 1 --branch "$XMRIG_VERSION" \
https://github.com/xmrig/xmrig.git /src/xmrig \
&& cmake -S /src/xmrig -B /src/xmrig/build \
-DCMAKE_BUILD_TYPE=Release \
&& cmake --build /src/xmrig/build --parallel 2 \
&& install /src/xmrig/build/xmrig /usr/local/bin/xmrig \
&& rm -rf /src/xmrig
RUN useradd --create-home miner
USER miner
ENTRYPOINT ["/usr/local/bin/xmrig"]
Choose a published release tag from the official XMRig project. Replace RELEASE_TAG below with that exact tag:
docker build --build-arg XMRIG_VERSION=RELEASE_TAG \
-t xmrig-local .
Using a specific release makes your build more predictable than automatically fetching the newest development code. This simple image keeps its build tools; you can optimize its size later.
3. Start mining with limits
Replace the pool, port, and wallet placeholders:
docker run -d \
--name xmrig \
--cpus="2" \
--memory="4g" \
xmrig-local \
--url POOL_HOST:TLS_PORT \
--user YOUR_PUBLIC_XMR_ADDRESS \
--pass x \
--tls \
--coin monero \
--threads=2 \
--randomx-mode=fast \
--no-huge-pages
Use your pool’s TLS port: TLS encrypts the connection. Follow its instructions if it requires a different password or worker-name format. Never supply your wallet seed phrase or private keys.
The CPU quota limits processing time, while --threads=2 selects two mining workers.
Monero’s RandomX mining algorithm needs about 2,080 MB for its fast-mode dataset, plus additional memory. The 4 GB limit leaves working room. Performance also benefits from roughly 2 MB of L3 cache, the processor’s shared fast memory, per mining thread.
4. Check operation before tuning
Read the output:
docker logs -f xmrig
Look for accepted shares: work your pool has successfully received. Check your pool dashboard too; payouts depend on its rules and minimum balance.
This starter setup disables huge pages, larger memory allocations that can improve speed. Hardware-tuning warnings may appear because the container runs without elevated permissions. Do not blindly add --privileged to remove them.
Monitor temperature, responsiveness, and electricity use. Stop or remove the container with:
docker stop xmrig
docker rm xmrig
The bottom line
Build from trusted source, use your own public wallet address, and start with tight resource limits. Confirm accepted shares before optimizing, and check a live profitability calculator rather than assuming Docker mining will cover your electricity costs.
