I would like to create a Docker image for a test network that has everything ready to go – pre-created accounts with ether already allocated.
The problem is there doesn't seem to be a way to do this the Docker Way(tm). In order to create ether out of thin air, I have to put addresses in the genesis.json 'alloc' section. In order to get the addresses, I have to create accounts with multiple invocations of geth and then manually edit genesis.json. Manual steps are not the Docker Way(tm), you are supposed to create a Docker file that does all these steps automatically.
My current best bet seems to be to to create a script that creates the accounts I need and the gets the account addresses from the geth command line option for that and then edits genesis.json on the fly. That seems… rather crude, and adds more tools to the docker image to do this (at least something that can parse JSON). Creation of accounts is not idempotent, so I can't just run the same script every time I start the container.
I'm sure the geth community has solved this problem for their own automated testing. Please share 🙂
I've read everything on the first page of this Google Search. They all have manual steps, which doesn't work for automation that Docker and automated test systems demand.
Best Answer
Here's the steps I used to create a Docker image that recreates a consistent test environment:
docker build -t ethereum/client-go:test .
to build an imagedocker run -i -t --entrypoint "/bin/bash" ethereum/client-go:test
docker cp
to copy off the entire contents of/root/.ethereum
to your host to the directory noted in the Dockerfile below.docker build
to create a new image. The new image now has the saved off starting state that can be reproduced as needed for your test environment.The Dockerfile:
I will attempt at some point to put an image on dockerhub so you don't have to do the above save run it.
Here's the script I use to build a docker container:
Here's the script I use to run a docker container instance.
and the script that runs geth in the container: