Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 19 additions & 32 deletions contrib/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,48 +1,35 @@
# example of Dockerfile that installs spesmilo electrumx 1.16.0
# ENV variables can be overridden on the `docker run` command
FROM python:3.10.14-bullseye
Copy link
Member

@f321x f321x Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use Python 3.14? It would provide better performance and wouldn't need to be updated anytime soon again, making the Dockerfile more "future proof".


FROM python:3.9.16-bullseye AS builder
WORKDIR /electrumx

WORKDIR /usr/src/app

# Install the libs needed by rocksdb (including development headers)
# Install all dependencies (build + runtime) for rocksdb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this still says rocksdb

RUN apt-get update \
&& apt-get -y --no-install-recommends install \
librocksdb-dev libsnappy-dev libbz2-dev libz-dev liblz4-dev \
&& apt-get install -y --no-install-recommends \
build-essential \
libleveldb-dev \
&& rm -rf /var/lib/apt/lists/*

RUN python -m venv venv \
&& venv/bin/pip install --no-cache-dir e-x[rapidjson,rocksdb]==1.16.0

# Copy the entire electrumx source tree
COPY . /electrumx
Copy link
Member

@f321x f321x Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the Dockerfile depend on the repository being available while the previous Dockerfile would fetch e-x from PyPI and work independently of the repository. What is your reasoning behind this change? I think its nice to have encapsulated Dockerfile so it doesn't depend on files being available on the host system.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: my local Dockerfile has stuff like this:

ARG ELECTRUMX_VERSION=fb28dc2d3d9facb08c861691793dcf749b6f0c44
RUN python3 -m pip install git+https://github.com/sombernight/electrumx.git@${ELECTRUMX_VERSION}#egg=e_x[rocksdb,dev]

Point being, you don't need a git clone even for running HEAD.


FROM python:3.9.16-slim-bullseye
# Install from local source with rapidjson support
RUN pip install --upgrade pip \
&& pip install "Cython<3.0" \
&& pip install /electrumx[rapidjson]

# Install the libs needed by rocksdb (no development headers or statics)
RUN apt-get update \
&& apt-get -y --no-install-recommends install \
librocksdb6.11 libsnappy1v5 libbz2-1.0 zlib1g liblz4-1 \
&& rm -rf /var/lib/apt/lists/*
# Data directory for electrumx
RUN mkdir -p /data

# Environment defaults
ENV SERVICES="tcp://:50001"
ENV COIN=Bitcoin
ENV DB_DIRECTORY=/var/lib/electrumx
ENV NET=mainnet
ENV DB_DIRECTORY=/data
ENV DAEMON_URL="http://username:password@hostname:port/"
ENV ALLOW_ROOT=true
ENV DB_ENGINE=rocksdb
ENV DB_ENGINE=leveldb
ENV MAX_SEND=10000000
ENV BANDWIDTH_UNIT_COST=50000
ENV CACHE_MB=2000

WORKDIR /usr/src/app
COPY --from=builder /usr/src/app .

VOLUME /var/lib/electrumx

RUN mkdir -p "$DB_DIRECTORY" && ulimit -n 1048576

CMD ["/usr/src/app/venv/bin/python", "/usr/src/app/venv/bin/electrumx_server"]

# build it with eg.: `docker build -t electrumx .`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep these examples/docs in the Dockerfile? They seem useful.

# run it with eg.:
# `docker run -d --net=host -v /home/electrumx/db/:/var/lib/electrumx -e DAEMON_URL="http://youruser:yourpass@localhost:8332" -e REPORT_SERVICES=tcp://example.com:50001 electrumx`
# for a clean shutdown, send TERM signal to the running container eg.: `docker kill --signal="TERM" CONTAINER_ID`
CMD ["electrumx_server"]