Skip to content

Instantly share code, notes, and snippets.

@konradkonrad
Last active October 27, 2015 16:34
Show Gist options
  • Save konradkonrad/54e623673741b3704726 to your computer and use it in GitHub Desktop.
Save konradkonrad/54e623673741b3704726 to your computer and use it in GitHub Desktop.
How to run a private pyethapp testcluster with docker-compose

Sometimes you maybe want to run your own little ethereum network. This is how you do it:

PREREQUISITES

  • install docker
  • install docker-compose
  • download docker-compose.yml

WHAT'S IN THE BOX?

The docker-compose.yml defines four services, which can start 4 slightly different configurations of pyethapp.

  1. bootstrap: A bootstrap node for your network, which also acts as a network bridge between the docker network and the host machine. !You can always only run one instance of this!

  2. eth: Simple "member" nodes, that will connect and relay blocks.

  3. miner: Same as above, but will also mine new blocks.

  4. debug: Non-mining member node, that has extensive logging activated. Start it (see RUN IT below), if you want to trace what is going on in the network. Then follow its log:

    docker logs --follow debug # instance name is 'debug'

RUN IT

Navigate to the downloaded docker-compose.yml and start your network with

docker-compose scale bootstrap=1 miner=2 eth=3

If you call docker-compose ps afterwards, you should see something like this:

docker-pyeth-cluster/ % docker-compose ps
             Name                           Command               State                         Ports                        
----------------------------------------------------------------------------------------------------------------------------
bootstrap                        /usr/local/bin/pyethapp -c ...   Up      127.0.0.1:30303->30303/tcp, 127.0.0.1:30303->30303/udp 
dockerpyethcluster_eth_1         /usr/local/bin/pyethapp -c ...   Up                                                         
dockerpyethcluster_eth_2         /usr/local/bin/pyethapp -c ...   Up                                                         
dockerpyethcluster_eth_3         /usr/local/bin/pyethapp -c ...   Up                                                         
dockerpyethcluster_miner_1       /usr/local/bin/pyethapp -c ...   Up                                                         
dockerpyethcluster_miner_2       /usr/local/bin/pyethapp -c ...   Up                                                         

In order to make sure, the network is indeed running and mining, call docker-compose logs. If you see things like the following in the log

miner_1     | INFO:pow.subprocess	nonce found	
miner_1     | INFO:pow.subprocess	sending nonce	
miner_1     | INFO:pow	nonce found	mining_hash='ffcb7228f9fd1756f9a5fb37e9119574486c9f71f84a3bada9a387ec6d0b933d'
miner_1     | New head: b88e43795484c92b5881b5e0cf9b41649199bd90ae3756fbbe1ff63a5e92770e 26
eth_1       | New head: b88e43795484c92b5881b5e0cf9b41649199bd90ae3756fbbe1ff63a5e92770e 26
bootstrap   | New head: b88e43795484c92b5881b5e0cf9b41649199bd90ae3756fbbe1ff63a5e92770e 26
eth_2       | New head: b88e43795484c92b5881b5e0cf9b41649199bd90ae3756fbbe1ff63a5e92770e 26
eth_1       | INFO:eth.chainservice	added	block=<Block(#26 b88e4379)> gas_used=0 txs=0
eth_1       | INFO:eth.chainservice	processing time	avg=0.04951763153076172 last=0.03158283233642578 max=0.09055614471435547 median=0.048686981201171875 min=0.02843189239501953
bootstrap   | INFO:eth.chainservice	added	block=<Block(#26 b88e4379)> gas_used=0 txs=0
bootstrap   | INFO:eth.chainservice	processing time	avg=0.04922186851501465 last=0.03145098686218262 max=0.06899094581604004 median=0.050950050354003906 min=0.021473169326782227
miner_2     | New head: b88e43795484c92b5881b5e0cf9b41649199bd90ae3756fbbe1ff63a5e92770e 26
eth_2       | INFO:eth.chainservice	added	block=<Block(#26 b88e4379)> gas_used=0 txs=0
eth_2       | INFO:eth.chainservice	processing time	avg=0.05634074409802755 last=0.047019004821777344 max=0.13787102699279785 median=0.049088478088378906 min=0.03183603286743164
miner_2     | INFO:eth.chainservice	added	block=<Block(#26 b88e4379)> gas_used=0 txs=0
miner_2     | INFO:eth.chainservice	processing time	avg=0.04983563423156738 last=0.04456615447998047 max=0.07030606269836426 median=0.05105710029602051 min=0.027590036392211914

then you know, your network is healthy.

PLAY WITH IT

interactive container

Start yourself an interactive (-it) instance, with a persistent data volume and create a new account like this:

docker run -it --rm --link bootstrap:bootstrap -v /tmp/pyethapp:/root/.config ethereum/client-python account new
    
    WARNING:eth.pow	using C++ implementation	
    INFO:config	setup default config	path='/root/.config/pyethapp'
    INFO:config	writing config	path='/root/.config/pyethapp/config.yaml'
    INFO:app	using data in	path='/root/.config/pyethapp'
    INFO:config	loading config	path='/root/.config/pyethapp'
    WARNING:accounts	keystore directory does not exist	directory='/root/.config/pyethapp/keystore'
    WARNING:accounts	no accounts found	
    INFO:app	registering service	service='accounts'
    Password to encrypt private key: 
    Repeat for confirmation: 
    INFO:accounts	adding account	account=<Account(address=b0ccb152cb6737b4f5bfac3496595802230d77c8, id=None)>
    Account creation successful
      Address: b0ccb152cb6737b4f5bfac3496595802230d77c8
           Id: None

Now run an instance with your account and mine yourself some ether:

docker run -it --rm --link bootstrap:bootstrap -v /tmp/pyethapp:/root/.config ethereum/client-python -c eth.network_id=1337 -b 'enode://288b97262895b1c7ec61cf314c2e2004407d0a5dc77566877aad1f2a36659c8b698f4b56fd06c4a0c0bf007b4cfb3e7122d907da3b005fa90e724441902eb19e@bootstrap:30303' -m 50 run --fake

native on the host

Since the bootstrap node publishes the ports to your local network, you should be able to connect to it from a client on the host system. Try this:

pyethapp -c eth.network_id=1337 -b 'enode://288b97262895b1c7ec61cf314c2e2004407d0a5dc77566877aad1f2a36659c8b698f4b56fd06c4a0c0bf007b4cfb3e7122d907da3b005fa90e724441902eb19e@localhost:30304' run --fake
bootstrap:
image: ethereum/client-python
container_name: bootstrap
entrypoint: /usr/local/bin/pyethapp
command: "-c eth.network_id=1337 -c node.privkey_hex=091bd6067cb4612df85d9c1ff85cc47f259ced4d4cd99816b14f35650f59c322 -b 'enode://288b97262895b1c7ec61cf314c2e2004407d0a5dc77566877aad1f2a36659c8b698f4b56fd06c4a0c0bf007b4cfb3e7122d907da3b005fa90e724441902eb19e@localhost:30303' run --fake"
ports:
- 127.0.0.1:30304:30303
- 127.0.0.1:30304:30303/udp
eth:
image: ethereum/client-python
links:
- bootstrap
entrypoint: /usr/local/bin/pyethapp
command: "-c eth.network_id=1337 -b 'enode://288b97262895b1c7ec61cf314c2e2004407d0a5dc77566877aad1f2a36659c8b698f4b56fd06c4a0c0bf007b4cfb3e7122d907da3b005fa90e724441902eb19e@bootstrap:30303' run --fake"
miner:
image: ethereum/client-python
links:
- bootstrap
entrypoint: /usr/local/bin/pyethapp
command: "-c eth.network_id=1337 -b 'enode://288b97262895b1c7ec61cf314c2e2004407d0a5dc77566877aad1f2a36659c8b698f4b56fd06c4a0c0bf007b4cfb3e7122d907da3b005fa90e724441902eb19e@bootstrap:30303' -m 50 run --fake"
debug:
image: ethereum/client-python
container_name: debug
links:
- bootstrap
entrypoint: /usr/local/bin/pyethapp
command: "-c eth.network_id=1337 -b 'enode://288b97262895b1c7ec61cf314c2e2004407d0a5dc77566877aad1f2a36659c8b698f4b56fd06c4a0c0bf007b4cfb3e7122d907da3b005fa90e724441902eb19e@bootstrap:30303' -l :debug,p2p:info run --fake"
@konradkonrad
Copy link
Author

@expsam
Copy link

expsam commented Oct 27, 2015

Is there a way to connect to the console of any of the nodes? I'd like to be able to view a node's ID or any other information for the nodes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment