I use and argument (ARG) in my Dockerfile to download a particular version of an application. I would like to tag my image with that version number. I end up writing something like that:

sh$ PHPBB_VERSION=3.2.4 &&
    sudo docker build --build-arg PHPBB_VERSION=${PHPBB_VERSION} \
                      --tag phpbb:${PHPBB_VERSION} - < dockerfiles/bootstrap

But I don't find that very elegant since you have to type the word PHPBB_VERSION no less than four times in this command, with all the possible errors introduced by a typo.

So, is there a more elegant solution to tag an image with the value of a Dockerfile argument?

FWIW, here is the relevant part of my Dockerfile:

sh$ cat dockerfiles/bootstrap
FROM php:7.2-cli

RUN echo "You are building phpBB version ${PHPBB_VERSION:?undefined}"
RUN wget -nv -O- \
      https://github.com/phpbb/phpbb/archive/release-${PHPBB_VERSION}.tar.gz | \
    tar xzf - --strip-components=1
  • 1
    Have you considered using a CI tool like Jenkins to build and tag images? Parameters can easily be set to a job and the process will be much more elegant than your current approach.
    – KatariaA
    Mar 12, 2019 at 17:33
  • 1
    FYI you can omit the && by passing -e to sudo. A good approach would be to create a shell script taking the version as argument
    – Tensibai
    Nov 6, 2019 at 23:06
  • Thanks for the comment. Actually, since I asked the question I chose to use a Makefile-based solution somewhat along the lines of the current top answer. A previous suggestion was to use a CI tool. But I must admit I lack knowledge in that area. Wouldn't that use a sledgehammer to kill a fly? Nov 7, 2019 at 0:46

2 Answers 2


You can use a Makefile for this:


    docker build \
        --build-arg PHPBB_VERSION=${PHPBB_VERSION} \
        --tag phpbb:${PHPBB_VERSION} - < Dockerfile


FROM php:7.2-cli                                                                           

ARG PHPBB_VERSION                                                                          

RUN wget -nv -O- https://github.com/phpbb/phpbb/archive/release-${PHPBB_VERSION}.tar.gz | \
    tar xzf - --strip-components=1                                                         

Then, in a shell: make build.


Why would you want to pass ARG as docker tag? Obviously it will at least be two times, first time with --build-arg and second time with --tag. So what you can do is that run this command inside a shell script so that you don't type this command again and again and just change value of $PHPBB_VETSION and run shell script.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.