Skip to content

Commit 41b6897

Browse files
varnavchainwhisper
authored andcommitted
Docker support (bnb-chain#175)
* Docker support * Add docker details to readme
1 parent 651930d commit 41b6897

File tree

6 files changed

+190
-0
lines changed

6 files changed

+190
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,28 @@ sh <(wget -qO- https://raw.githubusercontent.com/onggunhao/node-binary/master/in
2727
> In the future, we may release an official installer script
2828
> e.g. `sh <(wget -qO- https://get.binance.org)`
2929
30+
## Docker node
31+
32+
### Building locally
33+
34+
```
35+
git clone https://github.com/binance-chain/node-binary.git
36+
cd node-binary/docker && docker build . -t binance/binance-node
37+
```
38+
39+
### Run interactively
40+
41+
`docker run --rm -it --ulimit nofile=16000:16000 binance/binance-node`
42+
43+
### Run as daemon
44+
45+
```
46+
ufw allow 27146/tcp
47+
docker run -d --name binance-node -v binance-data:/opt/bnbchaind -e "BNET=prod" -p 27146:27146 -p 27147:27147 -p 26660:26660 --restart unless-stopped --security-opt no-new-privileges --ulimit nofile=16000:16000 binance/binance-node
48+
```
49+
50+
For more details see README.md in the docker directory.
51+
3052
## Manual Installation
3153

3254
We currently use this repo to store historical versions of the compiled `node-binaries`.

docker/Dockerfile

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# UPDATE ME when new version is out !!!!
2+
ARG BVER=0.6.3
3+
ARG CLIVER=0.6.3
4+
FROM ubuntu:18.04 as builder
5+
6+
# Dockerfile for running Binance node from binary packages under docker
7+
# https://docs.binance.org/fullnode.html#run-full-node-to-join-binance-chain
8+
# MIT license
9+
LABEL Maintainer = "Evgeny Varnavskiy <[email protected]>"
10+
LABEL Description="Docker image for Binance full and light nodes"
11+
LABEL License="MIT License"
12+
13+
ARG DEBIAN_FRONTEND=noninteractive
14+
15+
ARG BVER
16+
ARG CLIVER
17+
ARG NODETYPE=fullnode
18+
#ARG NODETYPE=lightnode
19+
20+
RUN apt-get update && apt-get install -y --no-install-recommends upx ca-certificates wget git git-lfs binutils
21+
RUN git lfs clone --depth 1 https://github.com/binance-chain/node-binary.git
22+
23+
# RUN upx /node-binary/cli/testnet/${CLIVER}/linux/tbnbcli \
24+
# && upx /node-binary/cli/prod/${CLIVER}/linux/bnbcli \
25+
# && upx /node-binary/${NODETYPE}/testnet/${BVER}/linux/bnbchaind \
26+
# && upx /node-binary/${NODETYPE}/prod/${BVER}/linux/bnbchaind
27+
28+
# Final stage
29+
30+
FROM ubuntu:18.04
31+
32+
ARG HOST_USER_UID=1000
33+
ARG HOST_USER_GID=1000
34+
35+
ARG BVER
36+
ARG CLIVER
37+
ENV BVER=$BVER
38+
ENV CLIVER=$CLIVER
39+
ARG NODETYPE=fullnode
40+
#ARG NODETYPE=lightnode
41+
ENV BNET=testnet
42+
#ENV BNET=prod
43+
ENV BNCHOME=/opt/bnbchaind
44+
45+
COPY --from=builder /node-binary/cli/testnet/${CLIVER}/linux/tbnbcli /node-binary/cli/testnet/${BVER}/linux/
46+
COPY --from=builder /node-binary/cli/prod/${CLIVER}/linux/bnbcli /node-binary/cli/prod/${BVER}/linux/
47+
COPY --from=builder /node-binary/${NODETYPE}/testnet/${BVER}/linux/bnbchaind /node-binary/fullnode/testnet/${BVER}/linux/
48+
COPY --from=builder /node-binary/${NODETYPE}/prod/${BVER}/linux/bnbchaind /node-binary/fullnode/prod/${BVER}/linux/
49+
COPY --from=builder /node-binary/${NODETYPE}/testnet/${BVER}/config/* /node-binary/fullnode/testnet/${BVER}/config/
50+
COPY --from=builder /node-binary/${NODETYPE}/prod/${BVER}/config/* /node-binary/fullnode/prod/${BVER}/config/
51+
COPY ./bin/*.sh /usr/local/bin/
52+
53+
RUN set -ex \
54+
&& chmod +x /usr/local/bin/*.sh \
55+
&& mkdir -p "$BNCHOME" \
56+
&& groupadd --gid "$HOST_USER_GID" bnbchaind \
57+
&& useradd --uid "$HOST_USER_UID" --gid "$HOST_USER_GID" --shell /bin/bash --no-create-home bnbchaind \
58+
&& chown -R bnbchaind:bnbchaind "$BNCHOME"
59+
60+
VOLUME ${BNCHOME}
61+
62+
# RPC service listen on port 27147 and P2P service listens on port 27146 by default.
63+
# Prometheus is enabled on port 26660 by default, and the endpoint is /metrics.
64+
65+
EXPOSE 27146 27147 26660
66+
67+
ENTRYPOINT ["entrypoint.sh"]

docker/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Evgeny Varnavskiy
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

docker/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# binance-node-docker
2+
3+
[Binance full node docs](https://docs.binance.org/fullnode.html#run-full-node-to-join-binance-chain)
4+
[Binance full node repo](https://github.com/binance-chain/node-binary)
5+
6+
Docker image for Binance Full Node
7+
8+
### Features:
9+
10+
* Spin up full Binance node with single command.
11+
* Works for testnet, prod, or both at once.
12+
* Small image about 100MB, compared to bigger than 6 GB official repository.
13+
* Easy updates
14+
15+
## Building locally
16+
17+
```
18+
git clone https://github.com/binance-chain/node-binary.git
19+
cd node-binary/docker && docker build . -t binance/binance-node
20+
```
21+
22+
### Run interactively
23+
24+
`docker run --rm -it --ulimit nofile=16000:16000 binance/binance-node`
25+
26+
### Run as daemon
27+
28+
```
29+
ufw allow 27146/tcp
30+
docker run -d --name binance-node -v binance-data:/opt/bnbchaind -e "BNET=prod" -p 27146:27146 -p 27147:27147 -p 26660:26660 --restart unless-stopped --security-opt no-new-privileges --ulimit nofile=16000:16000 binance/binance-node
31+
```
32+
33+
You can run both testnet and prod at once, use `-p 27147:27147` for publishing RPC port for one of them.
34+
35+
### Check logs
36+
37+
`docker logs -f binance-node`
38+
39+
### CLI access
40+
41+
```
42+
docker exec -it binance-node /bin/bash
43+
tbnbcli version
44+
```
45+
46+
use `tbnbcli` for testnet and `bnbcli` for prod
47+
48+
### Update
49+
50+
`docker stop binance-node && docker rm binance-node`, pull fresh image with `docker pull binance/binance-node` and then run again, data and configs in the volume `binance-data` are preserved.

docker/bin/entrypoint.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
source setup.sh
4+
echo "Running $0 in $PWD"
5+
set -ev
6+
su bnbchaind -c "/usr/local/bin/bnbchaind start --home ${BNCHOME}"

docker/bin/setup.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
if [ ! -d "${BNCHOME}/config/" ]; then
6+
mkdir -p ${BNCHOME}/config/
7+
cp /node-binary/fullnode/${BNET}/${BVER}/config/* ${BNCHOME}/config/
8+
chown -R bnbchaind:bnbchaind ${BNCHOME}/config/
9+
fi
10+
11+
ln -sf /node-binary/fullnode/${BNET}/${BVER}/linux/bnbchaind /usr/local/bin/bnbchaind
12+
chmod +x /usr/local/bin/bnbchaind
13+
14+
if [ ${BNET} == "testnet" ]; then
15+
ln -sf /node-binary/cli/${BNET}/${BVER}/linux/tbnbcli /usr/local/bin/tbnbcli
16+
chmod +x /usr/local/bin/tbnbcli
17+
else
18+
ln -sf /node-binary/cli/${BNET}/${BVER}/linux/bnbcli /usr/local/bin/bnbcli
19+
chmod +x /usr/local/bin/bnbcli
20+
fi
21+
22+
# Turn on console logging
23+
24+
sed -i 's/logToConsole = false/logToConsole = true/g' ${BNCHOME}/config/app.toml

0 commit comments

Comments
 (0)