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
[Enhancement]: DockerClient Java equivalent #1076
Comments
Indeed, Testcontainers for .NET does not expose the Docker client like Java does. That being said, there are two workarounds you can use in the meantime. Either way, you can use the image builder implementation to build an image first (the build cannot push the image, though). Or you can create your own using var dockerClientConfiguration = TestcontainersSettings.OS.DockerEndpointAuthConfig.GetDockerClientConfiguration(ResourceReaper.DefaultSessionId);
using var dockerClient = dockerClientConfiguration.CreateClient();
await dockerClient.Images.CommitContainerChangesAsync(new CommitContainerChangesParameters()); |
I gave it a try - commit + push (commit only means after Testcontainer exits the image is gone too):
|
Please make sure the new image does not contain the resource reaper session label, respectively set it to Edit: This builder configuration labels the resources and tells Ryuk to track and clean them up. If the label gets inherited, you need to somehow override the Guid as mentioned above. |
Even if I use Guid.Empty instead of ResourceReaper.DefaultSessionId on line 1 the things go away. Or are the labels in other places too (unfamiliar with this concept). I want the container to go away, but the committed image should stay. |
You need to override the resource label. Each resource, such as a container, image, network, or volume, is labeled to track it. I believe that when you commit a container, the new image inherits its labels. Please try disabling the cleanup for the container and check if this also keeps the image.
|
I just made the alternative I outlined in the initial comment work: I use Testcontainers to create the database via EF migrations, then export via DacFx
Now, I use the approach from https://www.kenmuse.com/blog/devops-sql-server-dacpac-docker (replacing dacpac with bacpac) with a few minor changes (ie the link to sqlpackage is no longer current, and USER root is needed for apt-get) to generate a new Docker image. Bonus of this approach: smaller image. |
Problem
I saw https://www.tomcools.be/post/june-2022-testcontainer-imagebuilder/ - this getDockerClient / commitCmd / pushImageCmd dance would be exactly what I wanted to do with a MSSQL Container - start, apply EF migration, seed some data, persist & push to registry for developers to pull.
Solution
I didn't see the functionality on .NET side (the obvious .DockerClient didn't exist), replicating the Java functionality would be great.
Benefit
Building container images on the fly using TestContainer.NET
Alternatives
tbh, haven't yet found a good one, eg via bacpac
Would you like to help contributing this enhancement?
No, in the sense that I don't know the internals of TestContainers.NET and likely wouldn't be able to contribute a PR.
The text was updated successfully, but these errors were encountered: