Docker에 bitcoin 데몬 설치하기
3월 20, 2023
In 기타 |
Docker에 bitcoin 데몬 설치하기
docker image 생성
docker image를 생성하기 위해 dockerfile를 작성하고 빌드합니다.
$ vi dockerfile
FROM ubuntu:18.04
MAINTAINER indexall
RUN mkdir /bitcoin
RUN mkdir /bitcoin/block
WORKDIR /bitcoin
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN apt-add-repository ppa:bitcoin/bitcoin
RUN apt-get update
RUN apt-get install -y bitcoin-qt bitcoind
RUN apt-get install -y vim
# docker build -t [tag] [path:dockerfile]
$ docker build -t ubuntu-bitcoin:1.0.0 .
docker image 실행
다음 명령어를 통해 생성된 이미지를 컨테이너로 만들고 인스턴스를 실행합니다.
$ docker run -it -d --name ubuntu-bitcoin ubuntu-bitcoin:1.0.0 /bin/bash
# 컨테이너 인스턴스가 실행되었는지 확인
$ docker ps
# 컨테이너 인스턴스 접속
$ docker exec -it ubuntu-bitcoin /bin/bash
bitcoind 실행
이후에는 접속된 docker 인스턴스에서 진행합니다.
$ vi /bitcoin/tnotify.sh
#!/bin/sh
echo "Type=$1, Arg=$2" >> /bitcoin/testnotify.log
$ chmod 755 /bitcoin/tnotify.sh
# -datadir= 는 block을 넣을 디렉토리로 설정
$ bitcoind -datadir=/bitcoin/block -daemon -server -testnet -txindex -reindex -rpcuser=indexall -rpcpassword=xxxxxx -alertnotify="/bitcoin/tnotify.sh ALERT %s" -walletnotify="/bitcoin/tnotify.sh WALLET %s" -blocknotify="/bitcoin/tnotify.sh BLOCK %s"
# 동작 확인
$ tail -f /bitcoin/block/testnet3/debug.log
bitcoin.conf 파일을 생성하면 bitcoin-cli 사용시 편리합니다.
bitcoin.conf 를 생성하면 -testnet -rpcuser -rpcpassword 등 을 넣지 않아도 됩니다.
$ vi ~/.bitcoin/bitcoin.conf
# 백그라운드 실행
daemon=1
# 테스트넷 여부
testnet=1
# rpcuser, passwrd설정
rpcuser=indexall
rpcpassword=xxxxxx
# 적용 여부 확인 (현재 동기화된 블럭수를 확인)
$ bitcoin-cli getblockchaininfo
bitcoind 종료
$ bitcoin-cli -testnet -rpcuser=indexall -rpcpassword=xxxxxx stop