Attempt to implement #332 - flattening layers

Please review, it implements basic flattening of layers, suitable for improvements of build process.

Example of flattening, It builds a new temporary image with many layers using Dockerfile and then it creates a single-layer new image that is diff from parent to the temporary image and uses settings from it:

cat Dockerfile | \
docker build --rm -t temporary:tag - && \
docker flatten parent:tag temporary:tag parent:newtag && \
docker rmi -f temporary:tag