Skip to content

Commit 0d3c3a2

Browse files
cdeckerNicolasDorier
authored andcommitted
docker: Add a usable dockerfile
This is based on @NicolasDorier's excellent proposal for a Dockerfile, sans the writing of a config file. Co-authored-by: Nicolas Dorier <[email protected]> Co-authored-by: Christian Decker <[email protected]> Signed-off-by: Christian Decker <[email protected]>
1 parent 1899e00 commit 0d3c3a2

File tree

4 files changed

+173
-7
lines changed

4 files changed

+173
-7
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Declare files that will always have CRLF line endings on checkout.
22
*.sh text eol=lf
33
*.py text eol=lf
4-
Makefile text eol=lf
4+
Makefile text eol=lf

Dockerfile

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
FROM alpine:3.7 as builder
2+
3+
RUN apk add --no-cache \
4+
ca-certificates \
5+
autoconf \
6+
automake \
7+
build-base \
8+
libressl \
9+
libtool \
10+
gmp-dev \
11+
python \
12+
python-dev \
13+
python3 \
14+
sqlite-dev \
15+
wget \
16+
git \
17+
file \
18+
gnupg \
19+
swig \
20+
zlib-dev
21+
22+
WORKDIR /opt
23+
24+
ENV BITCOIN_VERSION 0.16.0
25+
ENV BITCOIN_URL https://bitcoincore.org/bin/bitcoin-core-$BITCOIN_VERSION/bitcoin-$BITCOIN_VERSION-x86_64-linux-gnu.tar.gz
26+
ENV BITCOIN_SHA256 e6322c69bcc974a29e6a715e0ecb8799d2d21691d683eeb8fef65fc5f6a66477
27+
ENV BITCOIN_ASC_URL https://bitcoincore.org/bin/bitcoin-core-$BITCOIN_VERSION/SHA256SUMS.asc
28+
ENV BITCOIN_PGP_KEY 01EA5486DE18A882D4C2684590C8019E36C2E964
29+
30+
RUN mkdir /opt/bitcoin && cd /opt/bitcoin \
31+
&& wget -qO bitcoin.tar.gz "$BITCOIN_URL" \
32+
&& echo "$BITCOIN_SHA256 bitcoin.tar.gz" | sha256sum -c - \
33+
&& gpg --keyserver keyserver.ubuntu.com --recv-keys "$BITCOIN_PGP_KEY" \
34+
&& wget -qO bitcoin.asc "$BITCOIN_ASC_URL" \
35+
&& gpg --verify bitcoin.asc \
36+
&& BD=bitcoin-$BITCOIN_VERSION/bin \
37+
&& tar -xzvf bitcoin.tar.gz $BD/bitcoin-cli --strip-components=1 \
38+
&& rm bitcoin.tar.gz
39+
40+
ENV LITECOIN_VERSION 0.14.2
41+
ENV LITECOIN_URL https://download.litecoin.org/litecoin-0.14.2/linux/litecoin-0.14.2-x86_64-linux-gnu.tar.gz
42+
ENV LITECOIN_SHA256 05f409ee57ce83124f2463a3277dc8d46fca18637052d1021130e4deaca07b3c
43+
ENV LITECOIN_ASC_URL https://download.litecoin.org/litecoin-0.14.2/linux/litecoin-0.14.2-linux-signatures.asc
44+
ENV LITECOIN_PGP_KEY FE3348877809386C
45+
46+
# install litecoin binaries
47+
RUN mkdir /opt/litecoin && cd /opt/litecoin \
48+
&& wget -qO litecoin.tar.gz "$LITECOIN_URL" \
49+
&& echo "$LITECOIN_SHA256 litecoin.tar.gz" | sha256sum -c - \
50+
&& gpg --keyserver keyserver.ubuntu.com --recv-keys "$LITECOIN_PGP_KEY" \
51+
&& wget -qO litecoin.asc "$LITECOIN_ASC_URL" \
52+
&& gpg --verify litecoin.asc \
53+
&& BD=litecoin-$LITECOIN_VERSION/bin \
54+
&& tar -xzvf litecoin.tar.gz $BD/litecoin-cli --strip-components=1 --exclude=*-qt \
55+
&& rm litecoin.tar.gz
56+
57+
ENV LIGHTNINGD_VERSION=master
58+
59+
WORKDIR /opt/lightningd
60+
COPY . .
61+
62+
ARG DEVELOPER=0
63+
RUN ./configure && make -j3 DEVELOPER=${DEVELOPER} && cp lightningd/lightning* cli/lightning-cli /usr/bin/
64+
65+
FROM alpine:3.7
66+
67+
RUN apk add --no-cache \
68+
gmp-dev \
69+
sqlite-dev \
70+
inotify-tools \
71+
socat \
72+
bash \
73+
zlib-dev
74+
75+
ENV GLIBC_VERSION 2.27-r0
76+
ENV GLIBC_SHA256 938bceae3b83c53e7fa9cc4135ce45e04aae99256c5e74cf186c794b97473bc7
77+
ENV GLIBCBIN_SHA256 3a87874e57b9d92e223f3e90356aaea994af67fb76b71bb72abfb809e948d0d6
78+
# Download and install glibc (https://github.com/jeanblanchard/docker-alpine-glibc/blob/master/Dockerfile)
79+
RUN apk add --update curl && \
80+
curl -Lo /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub && \
81+
curl -Lo glibc.apk "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk" && \
82+
echo "$GLIBC_SHA256 glibc.apk" | sha256sum -c - && \
83+
curl -Lo glibc-bin.apk "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-bin-${GLIBC_VERSION}.apk" && \
84+
echo "$GLIBCBIN_SHA256 glibc-bin.apk" | sha256sum -c - && \
85+
apk add glibc-bin.apk glibc.apk && \
86+
/usr/glibc-compat/sbin/ldconfig /lib /usr/glibc-compat/lib && \
87+
echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf && \
88+
apk del curl && \
89+
rm -rf glibc.apk glibc-bin.apk /var/cache/apk/*
90+
91+
ENV LIGHTNINGD_DATA=/root/.lightning
92+
ENV LIGHTNINGD_PORT=9735
93+
94+
VOLUME [ "/root/.lightning" ]
95+
96+
COPY --from=builder /opt/lightningd/cli/lightning-cli /usr/bin
97+
COPY --from=builder /opt/lightningd/lightningd/lightning* /usr/bin/
98+
COPY --from=builder /opt/bitcoin/bin /usr/bin
99+
COPY --from=builder /opt/litecoin/bin /usr/bin
100+
COPY tools/docker-entrypoint.sh entrypoint.sh
101+
102+
EXPOSE 9735
103+
ENTRYPOINT [ "./entrypoint.sh" ]

README.md

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,58 @@ For the impatient here's the gist of it for Ubuntu and Debian:
6464
./configure
6565
make
6666

67-
Or if you like to throw `docker` into the mix:
67+
Or if you like to throw `docker` into the mix, you can use the offial docker image either directly or as a base layer for more complex images.
68+
The docker image is [elementsproject/lightningd](https://hub.docker.com/r/elementsproject/lightningd/) (from this [Dockerfile](Dockerfile)).
69+
Image tags with `-dev` at the end are images built with `DEVELOPER=1`.
70+
If you build the image yourself, you can use the build arg `DEVELOPER=1` to build c-lightning in developer mode.
6871

69-
sudo docker run \
70-
-v $HOME/.lightning:/root/.lightning \
71-
-v $HOME/.bitcoin:/root/.bitcoin \
72-
-p 9735:9735 \
73-
cdecker/lightningd:latest
72+
It has the following environment variable:
73+
74+
* `EXPOSE_TCP` default to false, if true, use expose c-lightning on port 9735. (Use this only for testing)
75+
76+
Here is an example of a docker-compose file with bitcoind and c-lightning on `testnet` which expose litecoin's rpc interface on default ports `18332` and c-lightning API on port `9735`:
77+
78+
```
79+
version: "3"
80+
services:
81+
bitcoind:
82+
image: nicolasdorier/docker-bitcoin:0.16.0
83+
environment:
84+
BITCOIN_EXTRA_ARGS: |
85+
testnet=1
86+
whitelist=0.0.0.0/0
87+
server=1
88+
rpcuser=rpcuser
89+
rpcpassword=rpcpass
90+
expose:
91+
- "18332"
92+
volumes:
93+
- "bitcoin_datadir:/data"
94+
95+
clightning_bitcoin:
96+
image: elementsproject/lightningd
97+
command:
98+
- lightningd
99+
- --bitcoin-rpcconnect=bitcoind
100+
- --bitcoin-rpcuser=rpcuser
101+
- --bitcoin-rpcpassword=rpcpass
102+
- --network=testnet
103+
- --alias=myawesomenode
104+
- --log-level=debug
105+
environment:
106+
EXPOSE_TCP: "true"
107+
expose:
108+
- "9735"
109+
volumes:
110+
- "clightning_bitcoin_datadir:/root/.lightning"
111+
- "bitcoin_datadir:/etc/bitcoin"
112+
links:
113+
- bitcoind
114+
115+
volumes:
116+
bitcoin_datadir:
117+
clightning_bitcoin_datadir:
118+
```
74119

75120
### Starting `lightningd`
76121

tools/docker-entrypoint.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
: "${EXPOSE_TCP:=false}"
4+
5+
if [ "$EXPOSE_TCP" == "true" ]; then
6+
set -m
7+
lightningd "$@" &
8+
9+
echo "C-Lightning starting"
10+
while read -r i; do if [ "$i" = "lightning-rpc" ]; then break; fi; done \
11+
< <(inotifywait -e create,open --format '%f' --quiet "$LIGHTNINGD_DATA" --monitor)
12+
echo "C-Lightning started"
13+
14+
socat "TCP4-listen:$LIGHTNINGD_PORT,fork,reuseaddr" "UNIX-CONNECT:$LIGHTNINGD_DATA/lightning-rpc" &
15+
fg %-
16+
else
17+
lightningd "$@"
18+
fi

0 commit comments

Comments
 (0)