2018-09-30 12:35:52 -04:00
# Docker Compose
2018-12-16 00:38:13 +04:00
With Docker Compose, you can spin up local testnets with a single command.
2018-09-30 12:35:52 -04:00
## Requirements
2019-03-27 18:51:57 +01:00
1. [Install tendermint ](../introduction/install.md )
2018-12-16 00:38:13 +04:00
2. [Install docker ](https://docs.docker.com/engine/installation/ )
3. [Install docker-compose ](https://docs.docker.com/compose/install/ )
2018-09-30 12:35:52 -04:00
## Build
2018-12-16 00:38:13 +04:00
Build the `tendermint` binary and, optionally, the `tendermint/localnode`
docker image.
2018-09-30 12:35:52 -04:00
Note the binary will be mounted into the container so it can be updated without
rebuilding the image.
```
cd $GOPATH/src/github.com/tendermint/tendermint
# Build the linux binary in ./build
make build-linux
2018-12-16 00:38:13 +04:00
# (optionally) Build tendermint/localnode image
2018-09-30 12:35:52 -04:00
make build-docker-localnode
```
## Run a testnet
To start a 4 node testnet run:
```
make localnet-start
```
2018-12-16 00:38:13 +04:00
The nodes bind their RPC servers to ports 26657, 26660, 26662, and 26664 on the
host.
2018-09-30 12:35:52 -04:00
This file creates a 4-node network using the localnode image.
2018-12-16 00:38:13 +04:00
The nodes of the network expose their P2P and RPC endpoints to the host machine
on ports 26656-26657, 26659-26660, 26661-26662, and 26663-26664 respectively.
2018-09-30 12:35:52 -04:00
To update the binary, just rebuild it and restart the nodes:
```
make build-linux
make localnet-stop
make localnet-start
```
## Configuration
2018-12-16 00:38:13 +04:00
The `make localnet-start` creates files for a 4-node testnet in `./build` by
calling the `tendermint testnet` command.
2018-09-30 12:35:52 -04:00
2018-12-16 00:38:13 +04:00
The `./build` directory is mounted to the `/tendermint` mount point to attach
the binary and config files to the container.
2018-09-30 12:35:52 -04:00
2018-12-16 00:38:13 +04:00
To change the number of validators / non-validators change the `localnet-start` Makefile target:
2018-09-30 12:35:52 -04:00
```
2018-12-16 00:38:13 +04:00
localnet-start: localnet-stop
@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
docker-compose up
```
2018-09-30 12:35:52 -04:00
2018-12-16 00:38:13 +04:00
The command now will generate config files for 5 validators and 3
non-validators network.
2018-09-30 12:35:52 -04:00
2018-12-16 00:38:13 +04:00
Before running it, don't forget to cleanup the old files:
2018-09-30 12:35:52 -04:00
2018-12-16 00:38:13 +04:00
```
cd $GOPATH/src/github.com/tendermint/tendermint
2018-09-30 12:35:52 -04:00
2018-12-16 00:38:13 +04:00
# Clear the build folder
rm -rf ./build/node*
2018-09-30 12:35:52 -04:00
```
2019-07-08 19:54:24 +02:00
## Configuring abci containers
2019-01-24 07:45:43 +01:00
2019-07-08 19:54:24 +02:00
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.
2019-01-24 07:45:43 +01:00
```
abci0:
container_name: abci0
image: "abci-image"
build:
context: .
dockerfile: abci.Dockerfile
command: < insert command to run your abci application >
networks:
localnet:
ipv4_address: 192.167.10.6
abci1:
container_name: abci1
image: "abci-image"
build:
context: .
dockerfile: abci.Dockerfile
command: < insert command to run your abci application >
networks:
localnet:
ipv4_address: 192.167.10.7
abci2:
container_name: abci2
image: "abci-image"
build:
context: .
dockerfile: abci.Dockerfile
command: < insert command to run your abci application >
networks:
localnet:
ipv4_address: 192.167.10.8
abci3:
container_name: abci3
image: "abci-image"
build:
context: .
dockerfile: abci.Dockerfile
command: < insert command to run your abci application >
networks:
localnet:
ipv4_address: 192.167.10.9
```
2019-07-08 19:54:24 +02:00
Override the [command ](https://github.com/tendermint/tendermint/blob/master/networks/local/localnode/Dockerfile#L12 ) in each node to connect to it's abci.
2019-01-24 07:45:43 +01:00
```
node0:
container_name: node0
image: "tendermint/localnode"
ports:
- "26656-26657:26656-26657"
environment:
- ID=0
- LOG=$${LOG:-tendermint.log}
volumes:
- ./build:/tendermint:Z
command: node --proxy_app=tcp://abci0:26658
networks:
localnet:
ipv4_address: 192.167.10.2
```
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 )
2018-09-30 12:35:52 -04:00
## Logging
2018-12-16 00:38:13 +04:00
Log is saved under the attached volume, in the `tendermint.log` file. If the
`LOG` environment variable is set to `stdout` at start, the log is not saved,
but printed on the screen.
2018-09-30 12:35:52 -04:00
## Special binaries
2018-12-16 00:38:13 +04:00
If you have multiple binaries with different names, you can specify which one
to run with the `BINARY` environment variable. The path of the binary is relative
to the attached volume.