github.com/btcsuite/btcd@v0.24.0/docs/using_docker.md (about) 1 # Using Docker 2 3 - [Using Docker](#using-docker) 4 - [Introduction](#introduction) 5 - [Docker volumes](#docker-volumes) 6 - [Known error messages when starting the btcd container](#known-error-messages-when-starting-the-btcd-container) 7 - [Examples](#examples) 8 - [Preamble](#preamble) 9 - [Full node without RPC port](#full-node-without-rpc-port) 10 - [Full node with RPC port](#full-node-with-rpc-port) 11 - [Full node with RPC port running on TESTNET](#full-node-with-rpc-port-running-on-testnet) 12 13 ## Introduction 14 15 With Docker you can easily set up *btcd* to run your Bitcoin full node. You can find the official *btcd* Docker images on Docker Hub [btcsuite/btcd](https://hub.docker.com/r/btcsuite/btcd). The Docker source file of this image is located at [Dockerfile](https://github.com/btcsuite/btcd/blob/master/Dockerfile). 16 17 This documentation focuses on running Docker container with *docker-compose.yml* files. These files are better to read and you can use them as a template for your own use. For more information about Docker and Docker compose visit the official [Docker documentation](https://docs.docker.com/). 18 19 ## Docker volumes 20 21 **Special diskspace hint**: The following examples are using a Docker managed volume. The volume is named *btcd-data* This will use a lot of disk space, because it contains the full Bitcoin blockchain. Please make yourself familiar with [Docker volumes](https://docs.docker.com/storage/volumes/). 22 23 The *btcd-data* volume will be reused, if you upgrade your *docker-compose.yml* file. Keep in mind, that it is not automatically removed by Docker, if you delete the btcd container. If you don't need the volume anymore, please delete it manually with the command: 24 25 ```bash 26 docker volume ls 27 docker volume rm btcd-data 28 ``` 29 30 For binding a local folder to your *btcd* container please read the [Docker documentation](https://docs.docker.com/). The preferred way is to use a Docker managed volume. 31 32 ## Known error messages when starting the btcd container 33 34 We pass all needed arguments to *btcd* as command line parameters in our *docker-compose.yml* file. It doesn't make sense to create a *btcd.conf* file. This would make things too complicated. Anyhow *btcd* will complain with following log messages when starting. These messages can be ignored: 35 36 ```bash 37 Error creating a default config file: open /sample-btcd.conf: no such file or directory 38 ... 39 [WRN] BTCD: open /root/.btcd/btcd.conf: no such file or directory 40 ``` 41 42 ## Examples 43 44 ### Preamble 45 46 All following examples uses some defaults: 47 48 - container_name: btcd 49 Name of the docker container that is be shown by e.g. ```docker ps -a``` 50 51 - hostname: btcd **(very important to set a fixed name before first start)** 52 The internal hostname in the docker container. By default, docker is recreating the hostname every time you change the *docker-compose.yml* file. The default hostnames look like *ef00548d4fa5*. This is a problem when using the *btcd* RPC port. The RPC port is using a certificate to validate the hostname. If the hostname changes you need to recreate the certificate. To avoid this, you should set a fixed hostname before the first start. This ensures, that the docker volume is created with a certificate with this hostname. 53 54 - restart: unless-stopped 55 Starts the *btcd* container when Docker starts, except that when the container is stopped (manually or otherwise), it is not restarted even after Docker restarts. 56 57 To use the following examples create an empty directory. In this directory create a file named *docker-compose.yml*, copy and paste the example into the *docker-compose.yml* file and run it. 58 59 ```bash 60 mkdir ~/btcd-docker 61 cd ~/btcd-docker 62 touch docker-compose.yaml 63 nano docker-compose.yaml (use your favourite editor to edit the compose file) 64 docker-compose up (creates and starts a new btcd container) 65 ``` 66 67 With the following commands you can control *docker-compose*: 68 69 ```docker-compose up -d``` (creates and starts the container in background) 70 71 ```docker-compose down``` (stops and delete the container. **The docker volume btcd-data will not be deleted**) 72 73 ```docker-compose stop``` (stops the container) 74 75 ```docker-compose start``` (starts the container) 76 77 ```docker ps -a``` (list all running and stopped container) 78 79 ```docker volume ls``` (lists all docker volumes) 80 81 ```docker logs btcd``` (shows the log ) 82 83 ```docker-compose help``` (brings up some helpful information) 84 85 ### Full node without RPC port 86 87 Let's start with an easy example. If you just want to create a full node without the need of using the RPC port, you can use the following example. This example will launch *btcd* and exposes only the default p2p port 8333 to the outside world: 88 89 ```yaml 90 version: "2" 91 92 services: 93 btcd: 94 container_name: btcd 95 hostname: btcd 96 build: https://github.com/btcsuite/btcd.git#master 97 restart: unless-stopped 98 volumes: 99 - btcd-data:/root/.btcd 100 ports: 101 - 8333:8333 102 103 volumes: 104 btcd-data: 105 ``` 106 107 ### Full node with RPC port 108 109 To use the RPC port of *btcd* you need to specify a *username* and a very strong *password*. If you want to connect to the RPC port from the internet, you need to expose port 8334(RPC) as well. 110 111 ```yaml 112 version: "2" 113 114 services: 115 btcd: 116 container_name: btcd 117 hostname: btcd 118 build: https://github.com/btcsuite/btcd.git#master 119 restart: unless-stopped 120 volumes: 121 - btcd-data:/root/.btcd 122 ports: 123 - 8333:8333 124 - 8334:8334 125 command: [ 126 "--rpcuser=[CHOOSE_A_USERNAME]", 127 "--rpcpass=[CREATE_A_VERY_HARD_PASSWORD]" 128 ] 129 130 volumes: 131 btcd-data: 132 ``` 133 134 ### Full node with RPC port running on TESTNET 135 136 To run a node on testnet, you need to provide the *--testnet* argument. The ports for testnet are 18333 (p2p) and 18334 (RPC): 137 138 ```yaml 139 version: "2" 140 141 services: 142 btcd: 143 container_name: btcd 144 hostname: btcd 145 build: https://github.com/btcsuite/btcd.git#master 146 restart: unless-stopped 147 volumes: 148 - btcd-data:/root/.btcd 149 ports: 150 - 18333:18333 151 - 18334:18334 152 command: [ 153 "--testnet", 154 "--rpcuser=[CHOOSE_A_USERNAME]", 155 "--rpcpass=[CREATE_A_VERY_HARD_PASSWORD]" 156 ] 157 158 volumes: 159 btcd-data: 160 ```