Attaching an Amazon EC2 EBS volume from Bash

Docker containers are disposed when stopped. We’ll need to store the blockchain outside of the container. Storing the blockchain on the host limits us to a single host machine. To overcome this limitation we store the blockchain on an Amazon AWS EBS volume and attach the volume to the host before starting the container. This is done by using a sidekick:

The script looks up its own instance ID using Amazon AWS and attaches the specified volume to itself. When receiving SIGTERM/SIGINT, which is caused by running docker stop from the host, it detaches the drive and exits gracefully. The source is available on Github and the Docker repository on Docker Hub.

Attaching an instance to an Amazon AWS ELB

As mentioned before the bitcoind container can run on any host. An elastic load balancer will provide a consistent endpoint for speaking with the container.

The ELB script is quite a bit simpler. It attaches (registers) the calling instance on start and detaches (deregisters) before exiting.

Running bitcoind inside Docker

I’ve also made a very simple Dockerfile for running bitcoind:

Piecing everything together

We now have three pieces of the puzzle; the bitcoind container, permanent storage and service discovery. I’m storing my AWS key and secret in etcd. Here’s the final Dockerfile:

The code is currently only used in our testing environment and might have some bugs we’ll find before moving to production.