Skip to content

Commit 9faaffd

Browse files
committed
reduce dockerfile layers
1 parent 58982dd commit 9faaffd

File tree

1 file changed

+23
-40
lines changed

1 file changed

+23
-40
lines changed

src/templates/Dockerfile

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,17 @@ ARG REPO
77
ARG BRANCH
88
ARG BITCOIN_URL
99

10-
# Base requirements
11-
RUN apt-get update && apt-get install -y --no-install-recommends \
10+
# install or build
11+
RUN set -ex \
12+
&& apt-get update && apt-get install -y --no-install-recommends \
1213
ca-certificates \
1314
wget \
14-
&& apt-get clean
15-
16-
# Download binary
17-
RUN if [ -n "${BITCOIN_URL}" ]; then \
15+
&& if [ -n "${BITCOIN_URL}" ]; then \
1816
wget "${BITCOIN_URL}/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}-${ARCH}-linux-gnu.tar.gz"; \
1917
tar -xzf "bitcoin-${BITCOIN_VERSION}-${ARCH}-linux-gnu.tar.gz" -C /usr/local --strip-components=1; \
20-
fi;
21-
22-
# Extra requirements to build from source
23-
RUN if [ -n "${REPO}" ]; then \
24-
apt-get update && apt-get install -y \
18+
fi \
19+
&& if [ -n "${REPO}" ]; then \
20+
apt-get install -y \
2521
automake \
2622
autotools-dev \
2723
build-essential \
@@ -35,12 +31,7 @@ RUN if [ -n "${REPO}" ]; then \
3531
libzmq3-dev \
3632
libqrencode-dev \
3733
libsqlite3-dev \
38-
pkg-config \
39-
&& apt-get clean; \
40-
fi;
41-
42-
# Build from source
43-
RUN if [ -n "${REPO}" ]; then \
34+
pkg-config; \
4435
mkdir build; \
4536
cd /build; \
4637
git clone --depth 1 --branch "${BRANCH}" "https://github.com/${REPO}"; \
@@ -54,12 +45,9 @@ RUN if [ -n "${REPO}" ]; then \
5445
--enable-suppress-external-warnings; \
5546
make -j$(nproc); \
5647
make install; \
57-
fi;
48+
fi
5849

59-
RUN rm -f /usr/local/bin/bitcoin-qt
60-
RUN rm -f /usr/local/bin/test_bitcoin*
61-
62-
# shrink image size a bit with a second stage
50+
# shrink image size with a second stage
6351
FROM debian:bookworm-slim
6452

6553
ARG UID=3338
@@ -68,42 +56,37 @@ ARG REPO
6856
# env var overrides
6957
ENV UID=$UID
7058
ENV GID=$GID
71-
7259
ENV BITCOIN_DATA=/home/bitcoin/.bitcoin
7360

74-
RUN groupadd --gid ${GID} bitcoin \
75-
&& useradd --create-home --no-log-init -u ${UID} -g ${GID} bitcoin \
76-
&& apt-get update && apt-get install -y --no-install-recommends \
61+
RUN set -ex \
62+
&& groupadd --gid ${GID} bitcoin \
63+
&& useradd --create-home --no-log-init -u ${UID} -g ${GID} bitcoin \
64+
&& apt-get update \
65+
&& apt-get install -y --no-install-recommends \
7766
gosu \
7867
tor \
79-
iproute2; \
80-
apt-get clean;
81-
82-
# libs needed to run source-build without depends
83-
RUN if [ -n "${REPO}" ]; then \
84-
apt-get update && apt-get install -y \
68+
iproute2 \
69+
&& if [ -n "${REPO}" ]; then \
70+
apt-get install -y --no-install-recommends \
8571
libboost-dev \
8672
libevent-dev \
8773
libdb5.3++-dev \
8874
libminiupnpc-dev \
8975
libnatpmp-dev \
9076
libzmq3-dev \
9177
libqrencode-dev \
92-
libsqlite3-dev \
93-
&& apt-get clean; \
94-
fi;
95-
96-
COPY --from=builder /usr/local/bin/bitcoin* /usr/local/bin/
78+
libsqlite3-dev; \
79+
fi \
80+
&& apt-get clean \
81+
&& rm -rf /var/cache/apt/* /var/lib/apt/lists/*
9782

83+
COPY --from=builder /usr/local/bin/bitcoind /usr/local/bin/bitcoin-cli /usr/local/bin/
9884
COPY docker-entrypoint.sh /entrypoint.sh
9985
COPY tor-keys/* /home/debian-tor/.tor/keys/
10086

10187
VOLUME ["/home/bitcoin/.bitcoin"]
102-
10388
EXPOSE 8332 8333 18332 18333 18443 18444 38333 38332
10489

10590
ENTRYPOINT ["/entrypoint.sh"]
106-
10791
RUN bitcoind -version | grep -E "Bitcoin Core( Daemon)? version v${BITCOIN_VERSION}"
108-
10992
CMD ["bitcoind"]

0 commit comments

Comments
 (0)