Today I learned about the subtleties of build arguments in Dockerfile definitions, specifically how the ARG instruction relates to - and is affected b

Using ARG in a Dockerfile - beware the gotcha | DJ Adams

submited by
Style Pass
2024-05-14 07:30:07

Today I learned about the subtleties of build arguments in Dockerfile definitions, specifically how the ARG instruction relates to - and is affected by - the FROM instruction. It's not entirely like a constant or a variable, in the way that I had thought.

I spent more than a coffee's worth of time trying to understand why my custom builds of a CAP Node.js container image weren't of the CAP version I was specifying, either implicitly with the default value I'd declared in the ARG instruction in the Dockerfile, or even explicitly with the --build-arg option on the command line.

The first variable declared with ARG here is DEBVER and represents a fairly common use case of allowing for different versions of a base image, illustrated here in being able to start from different versions of the Debian distribution, where the default version is to be 10.

The second variable CAPVER was something similar that I was using later in the build instructions (i.e. further on in the Dockerfile), to specify the particular version of CAP that I wanted to install. The actual instruction in my Dockerfile looked like this: RUN npm install -g @sap/cds-dk@{CAPVER}.

Leave a Comment