Run BP and Relay nodes in Docker using compose files. Spin up environment in under a Minute.
This guide is to enable users quickly spin up a cardano block producer node on the testnet , mainnet or mary_era using docker compose files. the beauty about using yaml files is you can easily bring up nodes and destroy nodes with one command. You can also easily test out different node versions on the fly without having to install etc
Special shout out to the guys at nessusio who have created one of the best cardano docker images i found as the images already come with scripts and tools like gLiview. nessusio dockerhub images
Another massive shout out to (tdiesler?). who has put together this wonderful guide on using the nessusio images to create a relay and block producing node using docker. All i have done is taking that guide and adapted it to use docker-compose yaml files. refer to this guide if you get stuck.
Right, now thats out of the way lets get started!!
-
Build 1 x docker block producing node version 1.27.0 updated 1.29.0
-
Build 1 x docker relay node version 1.27.0 updated 1.29.0
-
Create a docker network to allow nodes to communicate
-
Manually update topoloy files to get nodes communicating
-
Create docker volumes that will be mounted in the docker containers when started
-
Download the docker images
- Install docker if not already installed for you distribution. docker
- install docker-compose if not already installed. docker-compose
- ensure you have adequate disk space to download and store the cardano blockchain data, 10Gb +
-
first clone this reposotory and cd into the directory. git clone https://github.com/cardistack/cardano-nodes-docker.git && cardano-nodes-docker
-
- config - bin ( store any executables you want in here. Currently not used) - logs (if you decide to log to files instead of console (default)). - network(contains the topology files download from IOHK for the networks mentioned https://hydra.iohk.io/build/5416636/download/1/index.html into folders. You can manually modify these files like you would in a real node installation. - nodekeys (use this folder for your Block producer keys . Kes skey etc . ### WARNING!! this is ok for testnet . For mainnet dont store any private keys here. If you do for mainnet and get hacked you will lose funds. - scripts - export_env.sh (contains some environmental variables. Defaults are fine but you can edit to suite your needs)
-
- Docker-compose.yml ( this file contains the settings that will be used to build the nodes using version 1.27.0). Almost all the settings are automatically passed using variables so you dont really have to change anythng . However, if you want a node version other than 1.27 edit the section image: nessusio/cardano-node:1.27.0 to reflect. - i have manually defined the networks because i find its easier to use ip addresses in the topololy files to get the nodes communicating. - TIP: on the first run till the blockchain is synced on both nodes, leave the environmental variable CARDANO_BLOCK_PRODUCER=false under the cardano- node-BP: section .this is because you will not have the kes and vrf keys generated. if you do already have them, then you can place them under the nodekeys folder and modify the compose file accordinly. If not set both to sections to false , wait for the blockchain to sync, use cardano-cli in the nodes to generate the keys, stop the nodes, then set the CARDANO_BLOCK_PRODUCER=true under the cardano-node-BP section.
-
- CONTEXT=$PWD NETWORK=testnet (and enter . change to mainnet if yoou want to build for mainnet etc) - source scripts/export_env.sh ( this should load the enviroment variables into the current shell) - test you have the right network imported by typing, echo $NETWORK. this should echo the network you set.
-
- docker-compose up -d && docker-compose logs -f - if all goes well the nodes will be created and automatically started . just wait for the blockchain to sync
- you can exit out of console logging by pressing ctrl + c . reconnect anytime, docker-compose logs -f - docker ps (will show you list of running nodes)
- e.g connect to the BP by typing docker exec -it cardano-node-testnet-BP /bin/bash
- launch gLiview
- after blockchain is synced, change into the nodekeys directory and create the necessary keys for a block producer paying attention to the naming. - [How to create stakepool keys etc](https://docs.cardano.org/projects/cardano-node/en/latest/stake-pool-operations/keys_and_addresses.html) - once you have the keys, you can then shutdown the nodes and update the docker-compose.yml file by setting the environmental variable CARDANO_BLOCK_PRODUCER=true. start the nodes as before.
-
Stopping the nodes.
- docker-compose down ( This will remove the containers and networks but not delete the docker volumes)
- you can now stop and start the nodes when you want. - - you can also permanentlydelete the volumes. Note: this will clear all blockchain download and volumes will get recreated once you start the compose files. - docker volume rm (and volume name) . the volume names are defined in the yaml file. - volumes: node-mainnet-RELAY-db: node-testnet-RELAY-db: node-mainnet-RELAY-ipc: node-testnet-RELAY-ipc: node-mainnet-BP-db: node-testnet-BP-db: node-mainnet-BP-ipc: node-testnet-BP-ipc:
- Edit the topology files by using the IP adresses of the nodes defined in the docker yaml files.
- e.g BP on mainnet will be 192.168.33.13 etc
- ensure you also checkout the documents credited above .