Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - Build Arg in Source File

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

like image 437
Ashwini Khare Avatar asked Oct 26 '16 22:10

Ashwini Khare


1 Answers

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.

like image 142
johnharris85 Avatar answered Nov 16 '22 00:11

johnharris85