11

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

1
  • "Please provide a source image with from prior to commit" means that you have to use FORM before being able to use ARG in your Dockerfile. Commented Oct 26, 2016 at 23:12

1 Answer 1

17

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This has since been changed, see github.com/moby/moby/pull/31352
looks like ARG can come before FROM docs.docker.com/engine/reference/builder/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.