question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ARG still not working properly in FROM

See original GitHub issue

Description

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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
ThatDockerUsercommented, Sep 14, 2020

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:

ARG busyboxVersion=latest
FROM busybox:${busyboxVersion}
[INFO] DOCKER> [dmp-test:1.0.0-SNAPSHOT] "dmp-test": Created docker-build.tar in 160 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)]
0reactions
ThatDockerUsercommented, Sep 23, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Arg.Do() is not firing when expected in a When..Do for void ...
Yes, Arg.Do won't trigger in a Received(), as Received() is checking calls after the fact. Arg.Do only fires for future calls that are...
Read more >
ARG before FROM in Dockerfile doesn't behave as expected
Description It's documented that ARG can appear before FROM, so that arguments may be substituted into image names etc.
Read more >
pass arg to node not working - ROS Answers
Here is my launch file: Here is the command i'm running to launch this : roslaunch pure_vision pure_vision_single_image.launch ...
Read more >
Mo'arg not working properly with Collateral damage
I built a deck with a cool OTK idea, you draw until you have Collateral damage, terrorguard Escapee, and mo'arg artificer in hand, ......
Read more >
Overwatch: The Issue With the ARG and How to Fix It! - YouTube
The ARG is making people a bit grumpy now, to say the least. ... while what's been shown is cool its... well, not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found