github.com/okex/exchain@v1.8.0/libs/tendermint/docs/networks/docker-compose.md (about)

     1  ---
     2  order: 2
     3  ---
     4  
     5  # Docker Compose
     6  
     7  With Docker Compose, you can spin up local testnets with a single command.
     8  
     9  ## Requirements
    10  
    11  1. [Install tendermint](../introduction/install.md)
    12  2. [Install docker](https://docs.docker.com/engine/installation/)
    13  3. [Install docker-compose](https://docs.docker.com/compose/install/)
    14  
    15  ## Build
    16  
    17  Build the `tendermint` binary and, optionally, the `tendermint/localnode`
    18  docker image.
    19  
    20  Note the binary will be mounted into the container so it can be updated without
    21  rebuilding the image.
    22  
    23  ```
    24  cd $GOPATH/src/github.com/tendermint/tendermint
    25  
    26  # Build the linux binary in ./build
    27  make build-linux
    28  
    29  # (optionally) Build tendermint/localnode image
    30  make build-docker-localnode
    31  ```
    32  
    33  ## Run a testnet
    34  
    35  To start a 4 node testnet run:
    36  
    37  ```
    38  make localnet-start
    39  ```
    40  
    41  The nodes bind their RPC servers to ports 26657, 26660, 26662, and 26664 on the
    42  host.
    43  
    44  This file creates a 4-node network using the localnode image.
    45  
    46  The nodes of the network expose their P2P and RPC endpoints to the host machine
    47  on ports 26656-26657, 26659-26660, 26661-26662, and 26663-26664 respectively.
    48  
    49  To update the binary, just rebuild it and restart the nodes:
    50  
    51  ```
    52  make build-linux
    53  make localnet-stop
    54  make localnet-start
    55  ```
    56  
    57  ## Configuration
    58  
    59  The `make localnet-start` creates files for a 4-node testnet in `./build` by
    60  calling the `tendermint testnet` command.
    61  
    62  The `./build` directory is mounted to the `/tendermint` mount point to attach
    63  the binary and config files to the container.
    64  
    65  To change the number of validators / non-validators change the `localnet-start` Makefile target:
    66  
    67  ```
    68  localnet-start: localnet-stop
    69  	@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
    70  	docker-compose up
    71  ```
    72  
    73  The command now will generate config files for 5 validators and 3
    74  non-validators network.
    75  
    76  Before running it, don't forget to cleanup the old files:
    77  
    78  ```
    79  cd $GOPATH/src/github.com/tendermint/tendermint
    80  
    81  # Clear the build folder
    82  rm -rf ./build/node*
    83  ```
    84  
    85  ## Configuring abci containers
    86  
    87  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.
    88  
    89  ```
    90   abci0:
    91      container_name: abci0
    92      image: "abci-image"
    93      build:
    94        context: .
    95        dockerfile: abci.Dockerfile
    96      command: <insert command to run your abci application>
    97      networks:
    98        localnet:
    99          ipv4_address: 192.167.10.6
   100  
   101    abci1:
   102      container_name: abci1
   103      image: "abci-image"
   104      build:
   105        context: .
   106        dockerfile: abci.Dockerfile
   107      command: <insert command to run your abci application>
   108      networks:
   109        localnet:
   110          ipv4_address: 192.167.10.7
   111  
   112    abci2:
   113      container_name: abci2
   114      image: "abci-image"
   115      build:
   116        context: .
   117        dockerfile: abci.Dockerfile
   118      command: <insert command to run your abci application>
   119      networks:
   120        localnet:
   121          ipv4_address: 192.167.10.8
   122  
   123    abci3:
   124      container_name: abci3
   125      image: "abci-image"
   126      build:
   127        context: .
   128        dockerfile: abci.Dockerfile
   129      command: <insert command to run your abci application>
   130      networks:
   131        localnet:
   132          ipv4_address: 192.167.10.9
   133  
   134  ```
   135  
   136  Override the [command](https://github.com/tendermint/tendermint/blob/master/networks/local/localnode/Dockerfile#L12) in each node to connect to it's abci.
   137  
   138  ```
   139    node0:
   140      container_name: node0
   141      image: "tendermint/localnode"
   142      ports:
   143        - "26656-26657:26656-26657"
   144      environment:
   145        - ID=0
   146        - LOG=$${LOG:-tendermint.log}
   147      volumes:
   148        - ./build:/tendermint:Z
   149      command: node --proxy_app=tcp://abci0:26658
   150      networks:
   151        localnet:
   152          ipv4_address: 192.167.10.2
   153  ```
   154  
   155  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)
   156  
   157  ## Logging
   158  
   159  Log is saved under the attached volume, in the `tendermint.log` file. If the
   160  `LOG` environment variable is set to `stdout` at start, the log is not saved,
   161  but printed on the screen.
   162  
   163  ## Special binaries
   164  
   165  If you have multiple binaries with different names, you can specify which one
   166  to run with the `BINARY` environment variable. The path of the binary is relative
   167  to the attached volume.