Just to express this in the right context, now (since May 2017) you can achieve this with a clean docker from 05.17 ( https://github.com/moby/moby/pull/31352 )
The Docker file should look like (yes, the commands in that order):
ARG APP_VERSION ARG GIT_VERSION FROM app:$APP_VERSION-$GIT_VERSION
Then build is called using
docker build --build-arg APP_VERSION=1 --build-arg GIT_VERSION=c351dae2 .
Docker will try to build a build on the app:1-c351dae2 image app:1-c351dae2
Helped me unlimitedly reduce the logic of creating images.
source share