Module
Core
Proposal
ImageFromDockerfile should be configurable to build without the layer cache by default, through a configuration property read by TestcontainersConfiguration like the others:
# ~/.testcontainers.properties or classpath testcontainers.properties
imagefromdockerfile.nocache=true
or TESTCONTAINERS_IMAGEFROMDOCKERFILE_NOCACHE=true.
When set, ImageFromDockerfile.configure calls buildImageCmd.withNoCache(true) before running the user's buildImageCmdModifiers, so a call site can still turn the cache back on.
The default stays as it is today (cache on).
Limitations of the current implementation
With deleteOnExit (the default), an ImageFromDockerfile gets the session labels, and Ryuk removes it when the session ends.
Those labels are only on the final image. Its intermediate layers come from the daemon's build cache, so they are shared with every other session that builds the same Dockerfile on the same daemon.
When one session ends, Ryuk removes its image and the untagged parent layers go with it. If another session is building the same Dockerfile at that moment, its build can fail because the cached layers it is using no longer exist.
This happens on CI agents that run several builds of the same project on one Docker daemon.
The only way to avoid it today is to disable the cache on every ImageFromDockerfile:
new ImageFromDockerfile()
.withBuildImageCmdModifier(cmd -> cmd.withNoCache(true))
This has to be repeated at every call site. If one is forgotten, you get a random failure that only shows up when builds run at the same time.
It also can't reach images built inside Testcontainers modules and libraries.
With the property, a CI environment sets it once, on the agent or in the project's testcontainers.properties, and every ImageFromDockerfile is covered.
I'm happy to contribute the change.
Module
Core
Proposal
ImageFromDockerfileshould be configurable to build without the layer cache by default, through a configuration property read byTestcontainersConfigurationlike the others:or
TESTCONTAINERS_IMAGEFROMDOCKERFILE_NOCACHE=true.When set,
ImageFromDockerfile.configurecallsbuildImageCmd.withNoCache(true)before running the user'sbuildImageCmdModifiers, so a call site can still turn the cache back on.The default stays as it is today (cache on).
Limitations of the current implementation
With
deleteOnExit(the default), anImageFromDockerfilegets the session labels, and Ryuk removes it when the session ends.Those labels are only on the final image. Its intermediate layers come from the daemon's build cache, so they are shared with every other session that builds the same Dockerfile on the same daemon.
When one session ends, Ryuk removes its image and the untagged parent layers go with it. If another session is building the same Dockerfile at that moment, its build can fail because the cached layers it is using no longer exist.
This happens on CI agents that run several builds of the same project on one Docker daemon.
The only way to avoid it today is to disable the cache on every
ImageFromDockerfile:This has to be repeated at every call site. If one is forgotten, you get a random failure that only shows up when builds run at the same time.
It also can't reach images built inside Testcontainers modules and libraries.
With the property, a CI environment sets it once, on the agent or in the project's
testcontainers.properties, and everyImageFromDockerfileis covered.I'm happy to contribute the change.