Closed sdelamo closed 1 year ago
The default base image we use is not multi-platform.
We should change the default to eclipse-temurin:17-jre
The workaround would be to run dockerfile
copy the Dockerfile from build/docker/main/Dockerfile
to the root of the project and replace:
FROM openjdk:17-alpine
WORKDIR /home/app
COPY layers/libs /home/app/libs
COPY layers/classes /home/app/classes
COPY layers/resources /home/app/resources
COPY layers/application.jar /home/app/application.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/home/app/application.jar"]
with:
FROM eclipse-temurin:17-jre
WORKDIR /home/app
COPY layers/libs /home/app/libs
COPY layers/classes /home/app/classes
COPY layers/resources /home/app/resources
COPY layers/application.jar /home/app/application.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/home/app/application.jar"]
That's a brute-force workaround 😅 . You can simply do
tasks.named("dockerfile") {
baseImage = 'eclipse-temurin:17-jre'
}
it does not work:
Could not determine the dependencies of task ':dockerBuild'.
> Could not create task ':dockerfile'.
> Could not set unknown property 'baseImage' for task ':dockerfile' of type com.bmuschko.gradle.docker.tasks.image.Dockerfile.
it seems the config is:
tasks.named("dockerfile") {
from 'eclipse-temurin:17-jre'
}
but the generated Dockerfile
is incorrect.
it generates:
FROM openjdk:17-alpine
WORKDIR /home/app
COPY layers/libs /home/app/libs
COPY layers/classes /home/app/classes
COPY layers/resources /home/app/resources
COPY layers/application.jar /home/app/application.jar
EXPOSE 8080
FROM eclipse-temurin:17-jre
ENTRYPOINT ["java", "-jar", "/home/app/application.jar"]
Pretty sure this worked in Micronaut 3. Perhaps the documentation is left behind @melix ?
mmm, we do have baseImage
: https://github.com/micronaut-projects/micronaut-gradle-plugin/blob/1c6fba3323eabf7f543bd0fbfec89527d3a42b5a/docker-plugin/src/main/java/io/micronaut/gradle/docker/MicronautDockerfile.java#L162
but it seems that here the task type is the Docker plugin docker file, not ours :thinking:, so I think it doesn't work because you still have a Dockerfile
at the root.
Yeah, this works:
tasks.named("dockerfile") {
baseImage = "eclipse-temurin:17-jre"
}
and setting the Dockerfile
in the project root works as well.
I think we should change the base image to improve the user experience.
There are many problems reported with Alpine in any case, so changing the base image makes sense to me. I don't have the context why this was chosen in the first place.
Alpine became famous because it had small containers compared to that of the full distros.
But perhaps nowadays the situation is different. In fact, 17-jre
is smaller than 17-alpine
.
+1 for having a default base image with multi-platform support.
I add this to my build.gradle.kts
tasks.named<io.micronaut.gradle.docker.MicronautDockerfile>("dockerfile") { baseImage.set( "eclipse-temurin:17-jre") }
and it is working in version 4.1.0
if this base image it the recomendend for multi-platform support I vote for having it as default base image
But the above is not working when executing optimizedDockerBuild
`Step 1/8 : FROM openjdk:17-alpine
Task :app:optimizedDockerBuild FAILED
FAILURE: Build failed with an exception.
Could not build image: no matching manifest for linux/arm64/v8 in the manifest list entries `
Generate an app with the defaults.
Environment Information
Operating system: MacOS Ventura Architecture: Apple Silicon Mac Micronaut Gradle Plugin 4.0.2
Example Application
No response
Version
4.0.2