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.

179 lines
4.8 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. To update the binary, just rebuild it and restart the nodes:
  32. ```sh
  33. make build-linux
  34. make localnet-start
  35. ```
  36. ## Configuration
  37. The `make localnet-start` creates files for a 4-node testnet in `./build` by
  38. calling the `tendermint testnet` command.
  39. The `./build` directory is mounted to the `/tendermint` mount point to attach
  40. the binary and config files to the container.
  41. To change the number of validators / non-validators change the `localnet-start` Makefile target [here](../../makefile):
  42. ```makefile
  43. localnet-start: localnet-stop
  44. @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
  45. docker-compose up
  46. ```
  47. The command now will generate config files for 5 validators and 3
  48. non-validators. Along with generating new config files the docker-compose file needs to be edited.
  49. Adding 4 more nodes is required in order to fully utilize the config files that were generated.
  50. ```yml
  51. node3: # bump by 1 for every node
  52. container_name: node3 # bump by 1 for every node
  53. image: "tendermint/localnode"
  54. environment:
  55. - ID=3
  56. - LOG=${LOG:-tendermint.log}
  57. ports:
  58. - "26663-26664:26656-26657" # Bump 26663-26664 by one for every node
  59. volumes:
  60. - ./build:/tendermint:Z
  61. networks:
  62. localnet:
  63. ipv4_address: 192.167.10.5 # bump the final digit by 1 for every node
  64. ```
  65. Before running it, don't forget to cleanup the old files:
  66. ```sh
  67. # Clear the build folder
  68. rm -rf ./build/node*
  69. ```
  70. ## Configuring ABCI containers
  71. 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.
  72. ```yml
  73. abci0:
  74. container_name: abci0
  75. image: "abci-image"
  76. build:
  77. context: .
  78. dockerfile: abci.Dockerfile
  79. command: <insert command to run your abci application>
  80. networks:
  81. localnet:
  82. ipv4_address: 192.167.10.6
  83. abci1:
  84. container_name: abci1
  85. image: "abci-image"
  86. build:
  87. context: .
  88. dockerfile: abci.Dockerfile
  89. command: <insert command to run your abci application>
  90. networks:
  91. localnet:
  92. ipv4_address: 192.167.10.7
  93. abci2:
  94. container_name: abci2
  95. image: "abci-image"
  96. build:
  97. context: .
  98. dockerfile: abci.Dockerfile
  99. command: <insert command to run your abci application>
  100. networks:
  101. localnet:
  102. ipv4_address: 192.167.10.8
  103. abci3:
  104. container_name: abci3
  105. image: "abci-image"
  106. build:
  107. context: .
  108. dockerfile: abci.Dockerfile
  109. command: <insert command to run your abci application>
  110. networks:
  111. localnet:
  112. ipv4_address: 192.167.10.9
  113. ```
  114. Override the [command](https://github.com/tendermint/tendermint/blob/master/networks/local/localnode/Dockerfile#L12) in each node to connect to it's ABCI.
  115. ```yml
  116. node0:
  117. container_name: node0
  118. image: "tendermint/localnode"
  119. ports:
  120. - "26656-26657:26656-26657"
  121. environment:
  122. - ID=0
  123. - LOG=$${LOG:-tendermint.log}
  124. volumes:
  125. - ./build:/tendermint:Z
  126. command: node --proxy_app=tcp://abci0:26658
  127. networks:
  128. localnet:
  129. ipv4_address: 192.167.10.2
  130. ```
  131. Similarly do for node1, node2 and node3 then [run testnet](https://github.com/tendermint/tendermint/blob/master/docs/networks/docker-compose.md#run-a-testnet)
  132. ## Logging
  133. Log is saved under the attached volume, in the `tendermint.log` file. If the
  134. `LOG` environment variable is set to `stdout` at start, the log is not saved,
  135. but printed on the screen.
  136. ## Special binaries
  137. If you have multiple binaries with different names, you can specify which one
  138. to run with the `BINARY` environment variable. The path of the binary is relative
  139. to the attached volume.