Docker - Build Arg in Source File

docker, dockerfile

Solution

According to the docs, the first instruction needs to be `FROM` (or technically a parser directive, but not relevant here) so this approach likely isn't going to work. Probably some shell wrapper around `docker build...` with some `sed` command or something to insert the correct version, or a template of some kind.

Gareth Rushgrove had a nice talk at DockerCon16 on image build tooling that might be interesting.

Update (7/2/17): This is now possible to achieve since v17.06.

Problem

I'm trying to build a Docker container whose source tag I want to pass as a parameter. Build script: ``` docker build \ --pull=true \ ... --build-arg version=${version} ``` The Dockerfile: ``` ARG version FROM registry/repo:${version} ``` Running this gives me the error `Please provide a source image with`from`prior to commit`. Is there any way I can pass the version to pull as a build argument and use it? I'm on docker version `1.12`

Original source