Extract parts shared between master and shell

Most of the parts of this Dockerfile are shared between master and shell. I
refactored them out into a base image. Now master and shell just have to expose
their respective ports and define their entrypoint.