Skip to content

Instantly share code, notes, and snippets.

@chevdor
Last active March 1, 2022 07:06
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save chevdor/be461d11c56baecb0e7bbcb920e964fb to your computer and use it in GitHub Desktop.
Save chevdor/be461d11c56baecb0e7bbcb920e964fb to your computer and use it in GitHub Desktop.
Docker compose for a polkadot local chain

Substrate/Polkadot local chain

This gists contains a collection of docker-compose config for Polkadot and Substrate. You can find it here.

You may clone this gist with:

git clone git@gist.github.com:be461d11c56baecb0e7bbcb920e964fb.git

Then run each docker-compose config using:

docker-compose -f <file.yml> up --force-recreate
Note
Alternatively you can find below several one-liners that will download the config to your temp folder, pull and start containers, without the need to clone anything.
Note
I usually alias docker-compose as dcp and you will see dcp below. You can create this alias with alias dcp='docker-compose'
Warning
If you get any message similar to ERROR: Pool overlaps with other one on this address space, please run the following commands:
docker network ls | grep tmp | awk '{print $1}' | xargs docker network rm
Note
By default, all commands will pull the latest tag for the polkadot/substrate images. This may not always be what you want. To get the tag 1.2.3 you can prepend TAG=1.2.3 to the command. For instance TAG=bbqb dcp -f dcp-substrate-2nodes-noui.yml up --force-recreate
Note
After starting the commands including a UI, you may reach the UI at http://localhost:80/. You need however to adjust the settings in the UI in order to switch from the Hosted node to your local node.
Warning
It is likely that some of the docker-compose config no longer work for very old docker images.

Docker environment cleanup

You can cleanup your docker ENV using the following:

docker ps -a | grep "polkadot\|substrate" | awk '{print $1}' | xargs docker stop | xargs docker rm
docker network ls | grep "polkadot\|substrate\|tmp" | awk '{print $1}' | xargs docker network rm
docker volume ls | grep "polkadot\|substrate\|tmp" | awk '{print $2}' | xargs docker volume rm

This will NOT delete all your containers but only those related to polkadot or substrate.

Polkadot

2 nodes

2 nodes no UI
dcp -f dcp-polkadot-2nodes-noui.yml up --force-recreate
wget https://gist.githubusercontent.com/chevdor/be461d11c56baecb0e7bbcb920e964fb/raw/855b75b18a2e8f05b19633b2bbd8f00887aa9300/dcp-polkadot-2nodes-noui.yml -O /tmp/dcp-local.yml && docker-compose -f /tmp/dcp-local.yml up --force-recreate
2 nodes with UI
dcp -f dcp-polkadot-2nodes-ui.yml up --force-recreate
wget https://gist.githubusercontent.com/chevdor/be461d11c56baecb0e7bbcb920e964fb/raw/855b75b18a2e8f05b19633b2bbd8f00887aa9300/dcp-polkadot-2nodes-ui.yml -O /tmp/dcp-local.yml && docker-compose -f /tmp/dcp-local.yml up --force-recreate

5 nodes

5 nodes with UI
dcp -f dcp-polkadot-5nodes-ui.yml up --force-recreate
wget https://gist.githubusercontent.com/chevdor/be461d11c56baecb0e7bbcb920e964fb/raw/855b75b18a2e8f05b19633b2bbd8f00887aa9300/dcp-polkadot-5nodes-ui.yml -O /tmp/dcp-local.yml && docker-compose -f /tmp/dcp-local.yml up --force-recreate

Substrate

2 nodes

2 nodes no UI
dcp -f dcp-substrate-2nodes-noui.yml up --force-recreate
wget https://gist.githubusercontent.com/chevdor/be461d11c56baecb0e7bbcb920e964fb/raw/f10ebbe5b51f54e75cc06e14cf3a2f521b231cd9/dcp-substrate-2nodes-noui.yml -O /tmp/dcp-local.yml && docker-compose -f /tmp/dcp-local.yml up --force-recreate
2 nodes with UI
dcp -f dcp-substrate-2nodes-ui.yml up --force-recreate
wget https://gist.githubusercontent.com/chevdor/be461d11c56baecb0e7bbcb920e964fb/raw/f10ebbe5b51f54e75cc06e14cf3a2f521b231cd9/dcp-substrate-2nodes-ui.yml -O /tmp/dcp-local.yml && docker-compose -f /tmp/dcp-local.yml up --force-recreate
version: '3'
services:
node_alice:
image: chevdor/polkadot:${TAG:-latest}
container_name: alice
command: >
polkadot --chain=local --alice -d /data --ws-external --rpc-cors all --validator --node-key 0000000000000000000000000000000000000000000000000000000000000001
ports:
- "30333:30333"
- "9933:9933"
- "9944:9944"
volumes:
- "polkadot-data-alice:/data"
networks:
testing_net:
ipv4_address: 172.28.1.1
node_bob:
image: chevdor/polkadot:${TAG:-latest}
container_name: bob
command: >
polkadot --chain=local --bob --ws-external --rpc-cors all --validator -d /data --bootnodes '/ip4/172.28.1.1/tcp/30333/p2p/QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN'
ports:
- "30335:30333"
- "9935:9933"
- "9945:9944"
volumes:
- "polkadot-data-bob:/data"
links:
- "node_alice:alice"
networks:
testing_net:
ipv4_address: 172.28.1.2
volumes:
polkadot-data-alice:
polkadot-data-bob:
networks:
testing_net:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16
version: '3'
services:
node_alice:
image: chevdor/polkadot:${TAG:-latest}
container_name: alice
command: >
polkadot --chain=local --alice -d /data --ws-external --rpc-cors all --validator --node-key 0000000000000000000000000000000000000000000000000000000000000001
ports:
- "30333:30333"
- "9933:9933"
- "9944:9944"
volumes:
- "polkadot-data-alice:/data"
networks:
testing_net:
ipv4_address: 172.28.1.1
node_bob:
image: chevdor/polkadot:${TAG:-latest}
container_name: bob
command: >
polkadot --chain=local --bob -d /data --ws-external --rpc-cors all --validator --bootnodes '/ip4/172.28.1.1/tcp/30333/p2p/QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN'
ports:
- "30335:30333"
- "9935:9933"
- "9945:9944"
volumes:
- "polkadot-data-bob:/data"
links:
- "node_alice:alice"
networks:
testing_net:
ipv4_address: 172.28.1.2
ui:
container_name: ui
image: chevdor/polkadot-ui
ports:
- "80:80"
volumes:
polkadot-data-alice:
polkadot-data-bob:
networks:
testing_net:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16
version: '3'
services:
node_alice:
container_name: alice
image: chevdor/polkadot:${TAG:-latest}
ports:
- "30333:30333"
- "9933:9933"
- "9944:9944"
- "19615:9615"
volumes:
- "polkadot-data-alice:/data"
command: polkadot --chain=kusama-local --unsafe-ws-external --rpc-cors all --validator --alice --node-key 0000000000000000000000000000000000000000000000000000000000000001
networks:
testing_net:
ipv4_address: 172.28.1.1
node_bob:
container_name: bob
image: chevdor/polkadot:${TAG:-latest}
ports:
- "29615:9615"
volumes:
- "polkadot-data-bob:/data"
links:
- "node_alice:alice"
command: polkadot --chain=kusama-local --validator --bob --port 30344 --rpc-port 9935 --ws-port 9945 --bootnodes '/ip4/172.28.1.1/tcp/30333/p2p/QmRpheLN4JWdAnY7HGJfWFNbfkQCb6tFf4vvA6hgjMZKrR'
networks:
testing_net:
ipv4_address: 172.28.1.2
node_charlie:
container_name: charlie
image: chevdor/polkadot:${TAG:-latest}
ports:
- "39615:9615"
volumes:
- "polkadot-data-charlie:/data"
links:
- "node_alice:alice"
command: polkadot --chain=kusama-local --validator --charlie --bootnodes '/ip4/172.28.1.1/tcp/30333/p2p/QmRpheLN4JWdAnY7HGJfWFNbfkQCb6tFf4vvA6hgjMZKrR'
networks:
testing_net:
ipv4_address: 172.28.1.3
node_dave:
container_name: dave
image: chevdor/polkadot:${TAG:-latest}
ports:
- "49615:9615"
volumes:
- "polkadot-data-dave:/data"
links:
- "node_alice:alice"
command: polkadot --chain=kusama-local --validator --dave --bootnodes '/ip4/172.28.1.1/tcp/30333/p2p/QmRpheLN4JWdAnY7HGJfWFNbfkQCb6tFf4vvA6hgjMZKrR'
networks:
testing_net:
ipv4_address: 172.28.1.4
node_eve:
container_name: eve
image: chevdor/polkadot:${TAG:-latest}
ports:
- "59615:9615"
volumes:
- "polkadot-data-eve:/data"
links:
- "node_alice:alice"
command: polkadot --chain=kusama-local --validator --eve --bootnodes '/ip4/172.28.1.1/tcp/30333/p2p/QmRpheLN4JWdAnY7HGJfWFNbfkQCb6tFf4vvA6hgjMZKrR'
networks:
testing_net:
ipv4_address: 172.28.1.5
ui:
container_name: ui
image: chevdor/polkadot-ui
links:
- "node_alice:alice"
environment:
- WS_URL=ws://localhost:9944
ports:
- "80:80"
volumes:
polkadot-data-alice:
polkadot-data-bob:
polkadot-data-charlie:
polkadot-data-dave:
polkadot-data-eve:
networks:
testing_net:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16
version: '3'
services:
node_alice:
container_name: alice
image: chevdor/substrate:${TAG:-latest}
ports:
- "30333:30333"
- "9933:9933"
- "9944:9944"
volumes:
- "substrate-data-alice:/data"
command: substrate --chain=local --ws-external --rpc-cors all --validator --alice -d /data --node-key 0000000000000000000000000000000000000000000000000000000000000001
networks:
testing_net:
ipv4_address: 172.28.1.1
node_bob:
container_name: bob
image: chevdor/substrate:${TAG:-latest}
ports:
- "30335:30333"
- "9935:9933"
- "9945:9944"
volumes:
- "substrate-data-bob:/data"
links:
- "node_alice:alice"
command: substrate --chain=local --ws-external --rpc-cors all --validator --bob -d /data --bootnodes '/ip4/172.28.1.1/tcp/30333/p2p/QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN'
networks:
testing_net:
ipv4_address: 172.28.1.2
volumes:
substrate-data-alice:
substrate-data-bob:
networks:
testing_net:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16
version: '3'
services:
node_alice:
container_name: alice
image: chevdor/substrate:${TAG:-latest}
ports:
- "30333:30333"
- "9933:9933"
- "9944:9944"
volumes:
- "substrate-data-alice:/data"
command: substrate --chain=local --validator --alice -d /data --ws-external --rpc-cors all --node-key 0000000000000000000000000000000000000000000000000000000000000001
networks:
testing_net:
ipv4_address: 172.28.1.1
node_bob:
container_name: bob
image: chevdor/substrate:${TAG:-latest}
ports:
- "30334:30333"
- "9935:9933"
- "9945:9944"
volumes:
- "substrate-data-bob:/data"
links:
- "node_alice:alice"
command: substrate --chain=local --validator --bob -d /data --ws-external --rpc-cors all --bootnodes '/ip4/node_alice/tcp/30333/p2p/QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN'
networks:
testing_net:
ipv4_address: 172.28.1.2
ui:
image: chevdor/polkadot-ui
ports:
- "80:80"
volumes:
substrate-data-alice:
substrate-data-bob:
networks:
testing_net:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment