Dockerfile rebuilt every debug session AddDockerfile(..).WithLifetime(Persistent) #6928
-
We have a project that rarely changes but takes up to 30 seconds to start up. So when I read about WithLifetime(ContainerLifetime.Persistent) it seemed like a perfect fit. The only documentation I could find was the following:
As I understand it, I haven't changed the ContainerResource configuration and the container should be re-used. This is the code I use to set it up:
Have I missed something? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
Tested some more. |
Beta Was this translation helpful? Give feedback.
-
cc @danegsta I believe if you turn on verbose logging for DCP in your app settings, it'll show your why that is happening (likely because we change the image name) |
Beta Was this translation helpful? Give feedback.
-
I ran into the same issue. We have a Dockerfile and even though the contents (of the Dockerfile or any other resource that it copies in) are not changing it is still restarted every time. FROM alpine:3.22
CMD ["/bin/sh", "-c", "sleep 3600"] Notice that it does nothing except pull a base image and executes var builder = DistributedApplication.CreateBuilder(args);
builder.AddDockerfile("test", "./")
.WithLifetime(ContainerLifetime.Persistent)
.WithContainerName("test");
builder.Build().Run(); Even with this minimal setup the container is recreated every single time I run the app. It makes me wonder if the persistent lifetime will not work with For what it's worth, building outside of Aspire and just adding the container as mentioned by @Simon900225 preserves the container and works as expected. Any comment on whether my assumption is correct would be appreciated. |
Beta Was this translation helpful? Give feedback.
Yeah, verbose logging will report potential changes that triggered a rebuild of the container. Most likely, as David suggested, it’s that something about your Dockerfile is preventing your image builds from being cached (generally a COPY or ADD command pointing at a folder whose contents are changing between builds). Due to Docker build caching, building the same image multiple times with no changes to the Docker build context (the local folders Docker pulls file contents from) should result in the same final image ID.
This is admittedly a bit fuzzy compared to the other persistent container rebuild triggers and is something where we should consider adding configuration to optionally skip…