docker/docker — pull request #8803 by cpuguy83 (2014-10-27 18:51:22+00:00)
Title: Fixes #3639 Do not create new volumes on build

During builds when `VOLUME` is declared it is not treated any
differently than a normal volume. As such, for each new container
created as part of the build there is a new volume created for that
container.

Because of the way volumes work, this essentially makes a delcared
volume an immutable directory within the image since changes to the
data in the volume are not commited back to disk. This in turn makes
VOLUME delcarations highly positional and they must be declared at the
end of the Dockerfile.

The current behavior can also create a lot of added overhead if there is
any signficant amount of data in the image at the declared volume
location since this data gets automatically copied out onto the host as
part of the volution initialization.

This change introduces for the first time a differentiation from a build
container and a normal container.
This means a new HostConfig field called `BuildOnly` has been added.
This field is a boolean that can be used to change behavior of the
container creation depending on if it is for a build or not. In the case
of this change it checks if `container.hostConfig.BuildOnly` is true,
and if so, does not fully initialize the volume and instead just creates
the dir within the container's fs (if it doesn't exist).