Skip to content

Conversation

@tomasvanagas
Copy link

Hello,

I had issues building Docker image so I rewrote and simplified the Dockerfile.

Related PR #314

Best,
Tomas

@@ -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".

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

&& 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.


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.

@f321x
Copy link
Member

f321x commented Oct 30, 2025

Thanks for the PR.
I tried to build it but encounter this error because the Dockerfile is located in contrib and not the root of the repo:

user@hp:~/code/electrumx-fork/contrib$ docker build -t electrumx .
[+] Building 26.1s (9/10)                                                                                                                                                                          docker:default
 => [internal] load build definition from Dockerfile                                                                                                                                                         0.0s
 => => transferring dockerfile: 935B                                                                                                                                                                         0.0s
 => [internal] load metadata for docker.io/library/python:3.10.14-bullseye                                                                                                                                   2.3s
 => [internal] load .dockerignore                                                                                                                                                                            0.0s
 => => transferring context: 2B                                                                                                                                                                              0.0s
 => [1/6] FROM docker.io/library/python:3.10.14-bullseye@sha256:bbc02da4025cdf20e97441210db50373d35b52b0b5e4f28e1eb0548b397f2679                                                                            15.3s
 => => resolve docker.io/library/python:3.10.14-bullseye@sha256:bbc02da4025cdf20e97441210db50373d35b52b0b5e4f28e1eb0548b397f2679                                                                             0.0s
 => => sha256:bbc02da4025cdf20e97441210db50373d35b52b0b5e4f28e1eb0548b397f2679 9.08kB / 9.08kB                                                                                                               0.0s
 => => sha256:404522002efdc554619048f0be4ec6420f734ffe4dd704ce32f0dca965cf3273 2.52kB / 2.52kB                                                                                                               0.0s
 => => sha256:3615270c089487ffbbb9b927e7a938df00a14ecabcb0a137d1d6aefcefe7eb14 7.28kB / 7.28kB                                                                                                               0.0s
 => => sha256:ba83bbfca9443648a883d1404b33faa0f5e096a99a2b683e3bbaee8912bca845 55.08MB / 55.08MB                                                                                                            10.5s
 => => sha256:48e779000ed269823143d5ce9acd3ef6f6ff7465222482f7b02c10ba21f448cc 15.76MB / 15.76MB                                                                                                             8.2s
 => => sha256:6d691dff6d17d00b0cbbc4772eb805d97e02504d89ea3e5857cb97c943b74462 54.73MB / 54.73MB                                                                                                             2.1s
 => => sha256:54cfd30604666dfdd92bea930c06ee58dc927e0da651b862491af1648a4aca73 197.07MB / 197.07MB                                                                                                           7.5s
 => => sha256:de88d2367fa4c50f4bd8599f04cb7ea76a25e0df7b17a9cf99d9d013f829f4f3 6.05MB / 6.05MB                                                                                                               8.2s
 => => sha256:1098fe96b80e1084f8759acb0c08c39e496710952aebe45c26815e9162894199 232B / 232B                                                                                                                   8.6s
 => => sha256:203a2ed516c56c45ac72f52edef62a6eed450d6cafcef0c80454555d5aabeb2d 17.35MB / 17.35MB                                                                                                             8.9s
 => => sha256:cd8e006d545134a68892a2e5804296dc483cc3779ab6eca5bd7b70ef4e53a4e7 3.08MB / 3.08MB                                                                                                               9.5s
 => => extracting sha256:ba83bbfca9443648a883d1404b33faa0f5e096a99a2b683e3bbaee8912bca845                                                                                                                    0.8s
 => => extracting sha256:48e779000ed269823143d5ce9acd3ef6f6ff7465222482f7b02c10ba21f448cc                                                                                                                    0.1s
 => => extracting sha256:6d691dff6d17d00b0cbbc4772eb805d97e02504d89ea3e5857cb97c943b74462                                                                                                                    0.8s
 => => extracting sha256:54cfd30604666dfdd92bea930c06ee58dc927e0da651b862491af1648a4aca73                                                                                                                    2.2s
 => => extracting sha256:de88d2367fa4c50f4bd8599f04cb7ea76a25e0df7b17a9cf99d9d013f829f4f3                                                                                                                    0.1s
 => => extracting sha256:203a2ed516c56c45ac72f52edef62a6eed450d6cafcef0c80454555d5aabeb2d                                                                                                                    0.2s
 => => extracting sha256:1098fe96b80e1084f8759acb0c08c39e496710952aebe45c26815e9162894199                                                                                                                    0.0s
 => => extracting sha256:cd8e006d545134a68892a2e5804296dc483cc3779ab6eca5bd7b70ef4e53a4e7                                                                                                                    0.1s
 => [internal] load build context                                                                                                                                                                            0.0s
 => => transferring context: 14.11kB                                                                                                                                                                         0.0s
 => [2/6] WORKDIR /electrumx                                                                                                                                                                                 1.1s
 => [3/6] RUN apt-get update     && apt-get install -y --no-install-recommends         build-essential         libleveldb-dev     && rm -rf /var/lib/apt/lists/*                                             2.8s
 => [4/6] COPY . /electrumx                                                                                                                                                                                  0.1s
 => ERROR [5/6] RUN pip install --upgrade pip     && pip install "Cython<3.0"     && pip install /electrumx[rapidjson]                                                                                       4.5s 
------                                                                                                                                                                                                            
 > [5/6] RUN pip install --upgrade pip     && pip install "Cython<3.0"     && pip install /electrumx[rapidjson]:                                                                                                  
1.071 Requirement already satisfied: pip in /usr/local/lib/python3.10/site-packages (23.0.1)                                                                                                                      
1.262 Collecting pip                                                                                                                                                                                              
1.390   Downloading pip-25.3-py3-none-any.whl (1.8 MB)                                                                                                                                                            
1.643      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 7.0 MB/s eta 0:00:00                                                                                                                               
1.674 Installing collected packages: pip
1.674   Attempting uninstall: pip
1.675     Found existing installation: pip 23.0.1
1.751     Uninstalling pip-23.0.1:
2.005       Successfully uninstalled pip-23.0.1
2.497 Successfully installed pip-25.3
2.497 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
3.315 Collecting Cython<3.0
3.436   Downloading Cython-0.29.37-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl.metadata (3.1 kB)
3.492 Downloading Cython-0.29.37-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (1.9 MB)
3.734    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.9/1.9 MB 11.0 MB/s  0:00:00
3.748 Installing collected packages: Cython
4.068 Successfully installed Cython-0.29.37
4.068 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.
4.275 ERROR: Directory '/electrumx[rapidjson]' is not installable. Neither 'setup.py' nor 'pyproject.toml' found.
------
Dockerfile:16
--------------------
  15 |     # Install from local source with rapidjson support
  16 | >>> RUN pip install --upgrade pip \
  17 | >>>     && pip install "Cython<3.0" \
  18 | >>>     && pip install /electrumx[rapidjson]
  19 |     
--------------------
ERROR: failed to build: failed to solve: process "/bin/sh -c pip install --upgrade pip     && pip install \"Cython<3.0\"     && pip install /electrumx[rapidjson]" did not complete successfully: exit code: 1

@tomasvanagas
Copy link
Author

Thank you for reviewing, these are great points!

I'll respond in a single message to the reviews:

--- Main structural change:
The original Dockerfile was downloading electrumx source code from the pypi repository online and it was not building from the source code that we have in the parent directory. I found this odd because if I'm building the docker image - I want to build from the source code that I have in this directory and not from the repository (in case I want to tinker with the electrumx and modify it or just build the cutting edge version of electrumx).

--- Docker context:
So for building the image from the local source code we need to change a little bit how we build the image.
Previously the context for image was current ("electrumx/contrib") directory and the Dockerfile could not go outside and do anything. Now we need to set the context for the docker the parent directory ("electrumx/") so the docker can take the source code and build the image.

Command line for building (run this inside the "electrumx/contrib" directory):

docker build -f Dockerfile -t electrumx ..

--- RocksDB and LevelDB
I couldnt manage to make rocksdb work, only leveldb. Fixed a mistake in the comments.

--- Other small changes:

  • Upgrading to python 3.14: Thank you for point this out, I've updated and it works without any further changes
  • Examples in the comments bellow: Another great point, I've left updated comments
  • Cython: I realised that the cython is not needed so removed it.
  • Data directory: Updated to keep the original data directory path in place by default.

So these are my two cents. My motivation for rewriting the Dockerfile was that I couldn't build from the source code that I had git cloned in the parent directory and it was not clear how to do that.


VOLUME /var/lib/electrumx

RUN mkdir -p "$DB_DIRECTORY" && ulimit -n 1048576
Copy link
Member

@SomberNight SomberNight Oct 31, 2025

Choose a reason for hiding this comment

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

Are you sure raising the ulimit can be removed? I think it is needed for busy servers that serve lots of clients.
Alternatively it can also be specified as part of docker run: e.g. $ docker run --ulimit nofile=131072:131072

see

electrumx/docs/HOWTO.rst

Lines 118 to 126 in 592c4dc

Process limits
--------------
You must ensure the ElectrumX process has a large open file limit.
During sync it should not need more than about 1,024 open files. When
serving it will use approximately 256 for LevelDB plus the number of
incoming connections. It is not unusual to have 1,000 to 2,000
connections being served, so I suggest you set your open files limit
to at least 2,500.

Copy link
Author

Choose a reason for hiding this comment

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

Good point, I am not sure. My deployment does not serve many clients as well we do not run electrumx on huge chain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants