How to make a build arg mandatory during Docker build?

后端 未结 6 1938
后悔当初
后悔当初 2020-12-23 16:15

Is there any way to make a build argument mandatory during docker build? The expected behaviour would be for the build to fail if the argument is missing.

6条回答
  •  醉酒成梦
    2020-12-23 16:47

    I cannot comment yet because I do not have 50 reputation, but I would like to add onto @Jan Nash's solution because I had a little difficulty getting it to work with my image.

    If you copy/paste @Jan Nash's solution, it will work and spit out the error message that the build argument is not specified.

    What I want to add

    When I tried getting it to work on a CentOS 7 image (centos:7), Docker ran the RUN command without erroring out.

    Solution

    Ensure that you're executing the RUN command with the bash shell.

    RUN ["/bin/bash", "-c", ": ${MYUID:?Build argument needs to be set and not null.}"]

    I hope that helps for future incoming people. Otherwise, I believe @Jan Nash's solution is just brilliant.

提交回复
热议问题