I have the below Dockerfile and part of a customization of the bootBuildImage gradle task.
My goal is to build an image that contains curl (and a minimal shell, /bin/sh to execute I think).
I use the Kamal deploy tool to deploy containerized applications. The deploy tool uses curl to do healthchecks after starting the app container.
When I deploy with the Dockerfile (default), everything works fine. Because curl is included in amazoncorretto:23.
But it fails for the default container image built with bootBuildImage (a much smaller container image created, 200MB Vs. 300MB in my app).
I don’t understand how to customize the bootBuildImage task to produce an image with curl.
FROM amazoncorretto:23
WORKDIR /app
COPY customerservice/build/libs/A-0.0.1.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
// creates smaller docker images, buildpacks
tasks.named<org.springframework.boot.gradle.tasks.bundling.BootBuildImage>("bootBuildImage") {
imageName.set("U/A:latest")
publish.set(true)
docker {
publishRegistry {
username = "U"
password = System.getenv("DOCKER_REGISTRY_TOKEN")
}
}
builder= "paketobuildpacks/builder-jammy-full:latest"
environment.set(
mapOf(
"BP_IMAGE_LABELS" to "service="A"",
"BP_JVM_VERSION" to "23",
)
)
}
What I tried:
- See if there are some environment variables to include more
- builder= "paketobuildpacks/builder-jammy-full:latest", use another builder, for example I thought by using the jammy-full builder, since it includes curl, maybe the final output image contains curl, but that does not seem to be the case
- I tried setting runImage.set("amazoncorretto:23"), but that also failed.
2
Answers
I "solved" my main issue, by upgrading to Kamal 2 that does not rely on curl being available in the container image.
This does still not answer this question in particular about how to make container images with Paketo buildpacks "less optimized" by creating a less barebones image.
The builder that you use determines the stack that provides the base layers for both building and running the application. By default, Spring Boot uses the
builder-jammy-java-tiny
builder. It uses the tiny stack that produces the smallest images but does not contain tools likecurl
in its run image.The simplest way to build your application into an image that includes
curl
is with a builder that uses either the base or full stack, both of which includecurl
in their run images. For example, you could configure yourbootBuildImage
task to usepaketobuildpacks/builder-jammy-base
as its builder.If you want more control over exactly what’s included in the base layer of your application’s image, you can create your own stack and builder. This is certainly more work but, compared to just switching the
builder-jammy-base
, it provides far more control over exactly what will be in the image.