Docker - Build Arg in Source File

Ashwini Khare

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 withfromprior 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

johnharris85

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related