Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FROM --platform in Dockerfile causes error #1516

Closed
arauchberger opened this issue Jan 12, 2022 · 8 comments · Fixed by #1524
Closed

FROM --platform in Dockerfile causes error #1516

arauchberger opened this issue Jan 12, 2022 · 8 comments · Fixed by #1524
Assignees

Comments

@arauchberger
Copy link

Description

When trying to build from a Dockerfile (multistage) which is containing the FROM --platform=linux/amd64 instruction the build fails with the following error.
the intension to do so is that i work on a new MacBookPro with M1Pro Processor. i need to create at least an amd64 image - but would also be happy to create a native arm64 image (performances!!).

[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.38.1:build (docker-build) on project pitdata: Unable to check image [--platform=linux/arm64] : {"message":"no such image: --platform=linux/arm64: invalid reference format"} (Bad Request: 400) -> [Help 1]

Is this related to the fact that JIB is used for building?

Info

  • docker-maven-plugin version : 0.38.1
  • Maven version (mvn -v) : 3.6.3

Dockerfile

FROM --platform=linux/amd64 azul/zulu-openjdk-alpine:11 as packager

RUN { \
  java --version ; \
  echo "jlink version:" && \
  $JAVA_HOME/bin/jlink --version ; \
  }

ENV JAVA_MINIMAL=/opt/jre

# build modules distribution
RUN $JAVA_HOME/bin/jlink \
  --verbose \
  --add-modules \
  jdk.management.agent,java.base,java.net.http,java.sql,java.naming,java.desktop,java.xml,jdk.crypto.cryptoki,jdk.unsupported,java.management,java.security.jgss \
  --compress 2 \
  --strip-debug \
  --no-header-files \
  --no-man-pages \
  --output "$JAVA_MINIMAL"

#####################################
# Second stage
#
# adding the minimal "JRE" distr from the first stage
#####################################
FROM --platform=linux/amd64 alpine

# Runtime environment for JRE
ENV JAVA_MINIMAL=/opt/jre
ENV PATH="$PATH:$JAVA_MINIMAL/bin"

# install some utils
RUN apk --no-cache add curl iputils

# Copy the minimal-java to image
COPY --from=packager "$JAVA_MINIMAL" "$JAVA_MINIMAL"

# Execute Java Main
ENTRYPOINT ["/bin/sh","-c","java -version"]

Maven Plugin

                   <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <extensions>true</extensions>
                        <configuration>
                            <skip>${docker.skip}</skip>
                            <images>
                                <image>
                                    <!--
                                        <name>${docker.image.name}:${project.version}${version.suffix}</name>
                                        <name>${docker.image.name}:%l</name>
                                    -->
                                    <name>${docker.image.name}:%l</name>
                                    <alias>${docker.image.alias}</alias>
                                    <build>
                                        <tags>
                                            <tag>${project.version}${version.suffix}</tag>
                                            <tag>${docker.tag.native}</tag>
                                            <!--tag>${buildNumber}</tag-->
                                        </tags>
                                        <contextDir>${project.basedir}</contextDir>
                                        <dockerFile>${docker.dockerFile}</dockerFile>
                                        <args>
                                            <buildArtifact>${docker.buildArtifact}</buildArtifact>

                                            <!-- used as Labels in dockerfile -->
                                            <buildAppName>${project.artifactId}</buildAppName>
                                            <buildAppDesc>${project.description}</buildAppDesc>
                                            <buildOrg>${project.organization.name}</buildOrg>
                                            <buildBranch>${scmBranch}</buildBranch>
                                            <buildBranchVersion>${project.version}${version.suffix}</buildBranchVersion>
                                            <buildBranchRevision>${buildNumber}</buildBranchRevision>
                                            <buildDate>${maven.build.timestamp}</buildDate>
                                            <buildHost>${hostname}</buildHost>
                                            <buildOS>${os.name} ${os.version} (${os.arch})</buildOS>
                                        </args>
                                    </build>
                                </image>
                            </images>
                            <retries>3</retries>
                            <useColor>false</useColor>
                            <verbose>${docker.verbose}</verbose>
                            <skipPush>${docker.skipPush}</skipPush>
                        </configuration>
                        <executions>
                            <execution>
                                <id>docker-build</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>docker-push</id>
                                <phase>install</phase>
                                <goals>
                                    <goal>push</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
  • Docker version : 4.3.2 (72729)
  • If it's a bug, how to reproduce :
    • use my Dockerfile
@arauchberger
Copy link
Author

some more details: when i pass no platform-parameter i do get a "mixed up" image: (alpine for arm64) with an amd64-java installation which then does not run.
btw: this all works well when i use docker build on the command-line.

@rohanKanojia
Copy link
Member

I think we're not handling this use case when parsing from images from Dockerfile

public static List<String> extractBaseImages(File dockerFile, FixedStringSearchInterpolator interpolator, Map<String, String> argsFromBuildConfig) throws IOException {

@arauchberger
Copy link
Author

that's what i'm afraid of.
i do see no option to use your plugin when working on an arm64 architecture at the moment. i did some reading on related issues here (mainly #1502) but can not see a working option.
this is making me sad, since we have a deep integration of this plugin in our CI.

@rohanKanojia
Copy link
Member

rohanKanojia commented Jan 12, 2022

@arauchberger : We can fix this issue and create a new release.

Would you like to submit a PR to fix this issue?

@arauchberger
Copy link
Author

i'm not very familiar with creating PR's neither am i familiar with the plugins code ... i do not want to make more troubles then benefit. but i would be happy if you could fix this.

still ... i'm not 100% sure if this will work out very well.
i tried meanwhile on the command line:

  • with and without --platform=linux/amd64 on the FROM declaration in the Dockerfile !!
  • success to build for target-platform amd64. the build can be used on my M1-Mac (DockerDesktop is capable of running amd64 images via QEMU emulation, but performance is poor)
  • failure to build for target-platform arm64. the build completes successful, but Java is not executable, the packager-stage seems to be amd64, while the alpine-stage is arm64 --> incompatible
docker --debug build -f Dockerfile_simple --platform=linux/amd64 --no-cache -t pineit/simple:amd64-default . 
docker --debug build -f Dockerfile_simple --platform=linux/arm64 --no-cache -t pineit/simple:arm64-default . 

@arauchberger
Copy link
Author

another question related to this:

do you support platform as part of the build/buildOptions declaration?

<build>
   [...]
    <buildOptions>
        <!-- linux/arm64/v8 linux/arm64 linux/amd64 -->
        <platform>linux/amd64</platform>
    </buildOptions>
   [...]
</build>

@rohanKanojia
Copy link
Member

It's supported when doing build but I think while pulling images we're not passing this. We can fix this issue alongside this issue.

@arauchberger
Copy link
Author

FYI: i solved the problem with the arm64 cli build ...

azul/zulu-openjdk-alpine:11 is NOT available for arm64 😢 . i wonder that it is still downloading the amd64 version without telling, but so what.

@rohanKanojia rohanKanojia self-assigned this Feb 4, 2022
rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Feb 5, 2022
)

Right now we need to pull base images (ones specified in `FROM`
statements) before doing the actual build. DockerfileUtil doesn't seem
to be handling the case when an option is specified in `FROM` statement.
It just assumes second token to be image name.

Add check to ignore token starting with `--` so that it doesn't fail the
build. For specifiying pull platform it would need to be set in image
configuration build createImageOptions

Signed-off-by: Rohan Kumar <[email protected]>
rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Feb 6, 2022
)

Right now we need to pull base images (ones specified in `FROM`
statements) before doing the actual build. DockerfileUtil doesn't seem
to be handling the case when an option is specified in `FROM` statement.
It just assumes second token to be image name.

Add check to ignore token starting with `--` so that it doesn't fail the
build. For specifiying pull platform it would need to be set in image
configuration build createImageOptions

Signed-off-by: Rohan Kumar <[email protected]>
rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Feb 6, 2022
)

Right now we need to pull base images (ones specified in `FROM`
statements) before doing the actual build. DockerfileUtil doesn't seem
to be handling the case when an option is specified in `FROM` statement.
It just assumes second token to be image name.

Add check to ignore token starting with `--` so that it doesn't fail the
build. For specifiying pull platform it would need to be set in image
configuration build createImageOptions

Signed-off-by: Rohan Kumar <[email protected]>
rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Feb 6, 2022
)

Right now we need to pull base images (ones specified in `FROM`
statements) before doing the actual build. DockerfileUtil doesn't seem
to be handling the case when an option is specified in `FROM` statement.
It just assumes second token to be image name.

Add check to ignore token starting with `--` so that it doesn't fail the
build. For specifiying pull platform it would need to be set in image
configuration build createImageOptions

Signed-off-by: Rohan Kumar <[email protected]>
rohanKanojia added a commit that referenced this issue Feb 6, 2022
Right now we need to pull base images (ones specified in `FROM`
statements) before doing the actual build. DockerfileUtil doesn't seem
to be handling the case when an option is specified in `FROM` statement.
It just assumes second token to be image name.

Add check to ignore token starting with `--` so that it doesn't fail the
build. For specifiying pull platform it would need to be set in image
configuration build createImageOptions

Signed-off-by: Rohan Kumar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants