You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
5.0 KiB

  1. ---
  2. order: 2
  3. ---
  4. # Docker Compose
  5. With Docker Compose, you can spin up local testnets with a single command.
  6. ## Requirements
  7. 1. [Install tendermint](../introduction/install.md)
  8. 2. [Install docker](https://docs.docker.com/engine/installation/)
  9. 3. [Install docker-compose](https://docs.docker.com/compose/install/)
  10. ## Build
  11. Build the `tendermint` binary and, optionally, the `tendermint/localnode`
  12. docker image.
  13. Note the binary will be mounted into the container so it can be updated without
  14. rebuilding the image.
  15. ```sh
  16. # Build the linux binary in ./build
  17. make build-linux
  18. # (optionally) Build tendermint/localnode image
  19. make build-docker-localnode
  20. ```
  21. ## Run a testnet
  22. To start a 4 node testnet run:
  23. ```sh
  24. make localnet-start
  25. ```
  26. The nodes bind their RPC servers to ports 26657, 26660, 26662, and 26664 on the
  27. host.
  28. This file creates a 4-node network using the localnode image.
  29. The nodes of the network expose their P2P and RPC endpoints to the host machine
  30. on ports 26656-26657, 26659-26660, 26661-26662, and 26663-26664 respectively.
  31. The first node (`node0`) exposes two additional ports: 6060 for profiling using
  32. [`pprof`](https://golang.org/pkg/net/http/pprof), and `9090` - for Prometheus
  33. server (if you don't know how to start one check out ["First steps |
  34. Prometheus"](https://prometheus.io/docs/introduction/first_steps/)).
  35. To update the binary, just rebuild it and restart the nodes:
  36. ```sh
  37. make build-linux
  38. make localnet-start
  39. ```
  40. ## Configuration
  41. The `make localnet-start` creates files for a 4-node testnet in `./build` by
  42. calling the `tendermint testnet` command.
  43. The `./build` directory is mounted to the `/tendermint` mount point to attach
  44. the binary and config files to the container.
  45. To change the number of validators / non-validators change the `localnet-start` Makefile target [here](../../Makefile):
  46. ```makefile
  47. localnet-start: localnet-stop
  48. @if ! [ -f build/node0/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/tendermint:Z tendermint/localnode testnet --v 5 --n 3 --o . --populate-persistent-peers --starting-ip-address 192.167.10.2 ; fi
  49. docker-compose up
  50. ```
  51. The command now will generate config files for 5 validators and 3
  52. non-validators. Along with generating new config files the docker-compose file needs to be edited.
  53. Adding 4 more nodes is required in order to fully utilize the config files that were generated.
  54. ```yml
  55. node3: # bump by 1 for every node
  56. container_name: node3 # bump by 1 for every node
  57. image: "tendermint/localnode"
  58. environment:
  59. - ID=3
  60. - LOG=${LOG:-tendermint.log}
  61. ports:
  62. - "26663-26664:26656-26657" # Bump 26663-26664 by one for every node
  63. volumes:
  64. - ./build:/tendermint:Z
  65. networks:
  66. localnet:
  67. ipv4_address: 192.167.10.5 # bump the final digit by 1 for every node
  68. ```
  69. Before running it, don't forget to cleanup the old files:
  70. ```sh
  71. # Clear the build folder
  72. rm -rf ./build/node*
  73. ```
  74. ## Configuring ABCI containers
  75. To use your own ABCI applications with 4-node setup edit the [docker-compose.yaml](https://github.com/tendermint/tendermint/blob/master/docker-compose.yml) file and add image to your ABCI application.
  76. ```yml
  77. abci0:
  78. container_name: abci0
  79. image: "abci-image"
  80. build:
  81. context: .
  82. dockerfile: abci.Dockerfile
  83. command: <insert command to run your abci application>
  84. networks:
  85. localnet:
  86. ipv4_address: 192.167.10.6
  87. abci1:
  88. container_name: abci1
  89. image: "abci-image"
  90. build:
  91. context: .
  92. dockerfile: abci.Dockerfile
  93. command: <insert command to run your abci application>
  94. networks:
  95. localnet:
  96. ipv4_address: 192.167.10.7
  97. abci2:
  98. container_name: abci2
  99. image: "abci-image"
  100. build:
  101. context: .
  102. dockerfile: abci.Dockerfile
  103. command: <insert command to run your abci application>
  104. networks:
  105. localnet:
  106. ipv4_address: 192.167.10.8
  107. abci3:
  108. container_name: abci3
  109. image: "abci-image"
  110. build:
  111. context: .
  112. dockerfile: abci.Dockerfile
  113. command: <insert command to run your abci application>
  114. networks:
  115. localnet:
  116. ipv4_address: 192.167.10.9
  117. ```
  118. Override the [command](https://github.com/tendermint/tendermint/blob/master/networks/local/localnode/Dockerfile#L12) in each node to connect to it's ABCI.
  119. ```yml
  120. node0:
  121. container_name: node0
  122. image: "tendermint/localnode"
  123. ports:
  124. - "26656-26657:26656-26657"
  125. environment:
  126. - ID=0
  127. - LOG=$${LOG:-tendermint.log}
  128. volumes:
  129. - ./build:/tendermint:Z
  130. command: node --proxy-app=tcp://abci0:26658
  131. networks:
  132. localnet:
  133. ipv4_address: 192.167.10.2
  134. ```
  135. Similarly do for node1, node2 and node3 then [run testnet](#run-a-testnet).
  136. ## Logging
  137. Log is saved under the attached volume, in the `tendermint.log` file. If the
  138. `LOG` environment variable is set to `stdout` at start, the log is not saved,
  139. but printed on the screen.
  140. ## Special binaries
  141. If you have multiple binaries with different names, you can specify which one
  142. to run with the `BINARY` environment variable. The path of the binary is relative
  143. to the attached volume.