Last active
April 22, 2021 22:18
-
-
Save Danilo-Araujo-Silva/2864f0bb294344641435dde854ddecea to your computer and use it in GitHub Desktop.
Bitcoind with Tor network - Simple and customisable Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# useradd -r bitcoind | |
# docker builx build --no-cache -t bitcoind --platform linux/amd64 --build-arg USER_ID=$( id -u bitcoind ) --build-arg GROUP_ID=$( id -g bitcoind ) . | |
# docker run -dt --name=bitcoind bitcoind -v /path/to/bitcoin/volume/folder:/media/bitcoin | |
# | |
FROM ubuntu:latest | |
RUN apt update \ | |
&& apt install -y --no-install-recommends \ | |
ca-certificates \ | |
curl \ | |
gnupg \ | |
gosu \ | |
lsb-release | |
# Installing tor | |
RUN set -ex \ | |
&& echo "deb https://deb.torproject.org/torproject.org $(lsb_release -cs) main" >> /etc/apt/sources.list.d/tor.list \ | |
&& echo "# deb-src https://deb.torproject.org/torproject.org $(lsb_release -cs) main" >> /etc/apt/sources.list.d/tor.list \ | |
&& curl https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --import \ | |
&& gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | apt-key add - \ | |
&& apt update \ | |
&& apt install -y --no-install-recommends tor deb.torproject.org-keyring \ | |
&& apt clean \ | |
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | |
# Set using --platform | |
ARG TARGETPLATFORM | |
ARG BITCOIN_CORE_SIGNATURE=01EA5486DE18A882D4C2684590C8019E36C2E964 | |
ENV BITCOIN_VERSION=0.21.0 | |
ENV BITCOIN_HOME=/opt/bitcoin | |
ENV BITCOIN_VOLUME=/media/bitcoin | |
ENV BITCOIN_DATA_FOLDER=$BITCOIN_VOLUME/data | |
ENV BITCOIN_CONFIGURATION_FOLDER=$BITCOIN_VOLUME/configuration | |
ENV BITCOIN_CONFIGURATION_PATH=$BITCOIN_CONFIGURATION_FOLDER/bitcoin.conf | |
ENV PATH=$BITCOIN_HOME/bin:$PATH | |
# Installing bitcoind | |
RUN set -ex \ | |
&& if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then export BITCOIN_PLATFORM=x86_64-linux-gnu; fi \ | |
&& if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then export BITCOIN_PLATFORM=aarch64-linux-gnu; fi \ | |
&& if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then export BITCOIN_PLATFORM=arm-linux-gnueabihf; fi \ | |
&& for key in \ | |
01EA5486DE18A882D4C2684590C8019E36C2E964 \ | |
; do \ | |
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" || \ | |
gpg --batch --keyserver pgp.mit.edu --recv-keys "$key" || \ | |
gpg --batch --keyserver keyserver.pgp.com --recv-keys "$key" || \ | |
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$key" || \ | |
gpg --batch --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys "$key" ; \ | |
done \ | |
&& mkdir -p /tmp/bitcoin \ | |
&& cd /tmp/bitcoin \ | |
&& curl -SLO https://bitcoin.org/bin/bitcoin-core-$BITCOIN_VERSION/bitcoin-$BITCOIN_VERSION-$BITCOIN_PLATFORM.tar.gz \ | |
&& curl -SLO https://bitcoin.org/bin/bitcoin-core-$BITCOIN_VERSION/SHA256SUMS.asc \ | |
&& gpg --verify SHA256SUMS.asc \ | |
&& grep bitcoin-$BITCOIN_VERSION-$BITCOIN_PLATFORM.tar.gz SHA256SUMS.asc > SHA25SUM \ | |
&& sha256sum -c SHA25SUM \ | |
&& tar -xzf *.tar.gz -C /opt \ | |
&& ln -sv /opt/bitcoin-$BITCOIN_VERSION /opt/bitcoin \ | |
&& rm *.tar.gz *.asc \ | |
&& test_bitcoin --show_progress \ | |
&& rm -v /opt/bitcoin/bin/test_bitcoin /opt/bitcoin/bin/bitcoin-qt \ | |
&& rm -rf /tmp/bitcoin \ | |
&& mkdir -p $BITCOIN_DATA_FOLDER \ | |
&& mkdir -p $BITCOIN_CONFIGURATION_FOLDER | |
# Ports definitions (respectively RPC and Node connections): | |
# mainnet: 8332, 8333 | |
# testnet: 18332, 18333 | |
# regtest: 18443 18444 | |
# signet: 38332, 38333 | |
EXPOSE 8332 8333 18332 18333 18443 18444 38332 38333 | |
WORKDIR $BITCOIN_DATA_FOLDER | |
VOLUME ["$BITCOIN_DATA_FOLDER"] | |
# Set using --build-arg GROUP_ID=$( id -u bitcoind ) | |
ARG GROUP_ID=1000 | |
# Set using --build-arg USER_ID=$( id -u bitcoind ) | |
ARG USER_ID=1000 | |
RUN \ | |
groupadd -g ${GROUP_ID} bitcoin \ | |
&& useradd -u ${USER_ID} -g bitcoin -d $BITCOIN_DATA_FOLDER bitcoin | |
RUN bitcoind -version | grep "Bitcoin Core version v$BITCOIN_VERSION" | |
CMD \ | |
service tor start \ | |
&& bitcoind -conf=$BITCOIN_CONFIGURATION_PATH -datadir=$BITCOIN_DATA_FOLDER |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment