From 26684c4ad87173225c6f3cfd410d77353bf4691b Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Mon, 8 Apr 2024 19:15:56 +0200 Subject: [PATCH] docs: Add reading file from a container --- docs/api/create_docker_container.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/api/create_docker_container.md b/docs/api/create_docker_container.md index 82679a07a..cbd752c6a 100644 --- a/docs/api/create_docker_container.md +++ b/docs/api/create_docker_container.md @@ -55,6 +55,18 @@ _ = new ContainerBuilder() .WithResourceMapping(Encoding.Default.GetBytes("{}"), "/app/appsettings.json"); ``` +## Reading files from the container + +The `IContainer` interface offers a `ReadFileAsync(string, CancellationToken)` method to read files from the container. The implementation returns the read bytes. Either process the read bytes in-memory or persist them to the disk. + +```csharp title="Reading a file" +var readBytes = await container.ReadFileAsync("/app/appsettings.json") + .ConfigureAwait(false); + +await File.WriteAllBytesAsync("appsettings.json", readBytes) + .ConfigureAwait(false); +``` + ## Examples An NGINX container that binds the HTTP port to a random host port and hosts static content. The example connects to the web server and checks the HTTP status code.