ARG still not working properly in FROM
See original GitHub issueDescription
This was already discussed extensively since 2017 at #859 and partially fixed by #1299 with a new release today. I tested it, and there are several cases where it still does not work.
MWE pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>dmp-test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<java.version>1.8</java.version>
<resource.delimiter>@</resource.delimiter>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<busybox.version>latest</busybox.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.34.0</version>
<configuration>
<images>
<image>
<alias>${project.artifactId}</alias>
<name>${project.artifactId}:${project.version}</name>
<build>
<contextDir>${project.basedir}</contextDir>
<args>
<busyboxVersion>${busybox.version}</busyboxVersion>
<busyboxVersionName>${busybox.version}</busyboxVersionName>
</args>
</build>
</image>
</images>
</configuration>
</plugin>
</plugins>
</build>
</project>
I want to use busyboxVersion, as supplied by Maven, in my Dockerfile, so I do this:
ARG busyboxVersion
FROM busybox:${busyboxVersion}
But upon building, I get this:
[INFO] DOCKER> [dmp-test:1.0.0-SNAPSHOT] "dmp-test": Created docker-build.tar in 83 milliseconds
[ERROR] DOCKER> Unable to check image [busybox:${busyboxVersion}] : {"message":"no such image: busybox:${busyboxVersion}: invalid reference format"} (Bad Request: 400) [{"message":"no such image: busybox:${busyboxVersion}: invalid reference format"} (Bad Request: 400)]
Apparently, the ARG is not resolved, although this is the correct format as per the documentation. So, I change it to this:
ARG busyboxVersion
FROM busybox:$busyboxVersion
And get this:
[INFO] DOCKER> [dmp-test:1.0.0-SNAPSHOT] "dmp-test": Created docker-build.tar in 122 milliseconds
[ERROR] DOCKER> Unable to check image [busybox:] : {"message":"no such image: busybox:: invalid reference format"} (Bad Request: 400) [{"message":"no such image: busybox:: invalid reference format"} (Bad Request: 400)]
The ARG is now resolved, but has no content. Hence, I test this:
ARG busyboxVersion
FROM busybox:latest
ARG busyboxVersionName
LABEL busyboxVersion=${busyboxVersion}
LABEL busyboxVersionName=${busyboxVersionName}
The image is now built (since the version is again hard-coded), but upon inspecting it in Docker, I get this:
"Labels": {
"busyboxVersion": "",
"busyboxVersionName": "latest"
}
Once again, the ARG was resolved to an empty string, while the second ARG was interpreted correctly. I further this test like so:
FROM busybox:latest
ARG busyboxVersion
ARG busyboxVersionName
LABEL busyboxVersion=${busyboxVersion}
LABEL busyboxVersionName=${busyboxVersionName}
Now inspecting the Docker image, everything is alright:
"Labels": {
"busyboxVersion": "latest",
"busyboxVersionName": "latest"
}
Info
- d-m-p version : 0.34.0
- Maven version (
mvn -v
) :
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: C:\Program Files\apache-maven-3.6.3\bin\..
Java version: 11.0.7, vendor: AdoptOpenJDK, runtime: C:\Program Files\AdoptOpenJDK\jdk-11.0.7.10-hotspot
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
- Docker version : 19.03.12
- If it’s a bug, how to reproduce : see above
- If it’s a feature request, what is your use case : -
- Sample project : see above
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7
Thanks for taking this on, I will also note here that the variable format with the braces does not work irrespective of the POM usage, such as in this:
Maybe that is also a bug within Docker, but any ARG configured prior to the FROM remains valid in the FROM. The PR addresses this, so I hope it can be merged and released soon.