Files

209 lines
4.5 KiB
Markdown
Raw Permalink Normal View History

2026-06-26 17:28:07 -04:00
# Session
2026-09-29 07:14:54 -07:00
Represents a WSL-backed container host session.
2026-09-29 07:14:54 -07:00
## Session constructor
2026-06-26 17:28:07 -04:00
2026-09-29 07:14:54 -07:00
The settings object must not be null.
2026-09-29 07:14:54 -07:00
```cpp
Session session{ sessionSettings };
```
2026-06-26 17:28:07 -04:00
2026-09-29 07:14:54 -07:00
## Session::Start()
2026-09-29 07:14:54 -07:00
Starts the session. Calling this method more than once throws an exception.
2026-06-26 17:28:07 -04:00
```cpp
session.Start();
```
2026-09-29 07:14:54 -07:00
## Session::Terminate()
Terminates the session.
```cpp
session.Terminate();
```
## Session::CreateContainer(ContainerSettings)
Creates a container object owned by the session.
2026-06-26 17:28:07 -04:00
```cpp
auto container = session.CreateContainer(containerSettings);
```
2026-09-29 07:14:54 -07:00
## Session::OpenContainer(hstring, ProcessOutputMode)
Opens an existing container by name, full ID, or unambiguous partial ID prefix. The output mode
controls how the opened container's init-process I/O is exposed when it is started.
```cpp
auto opened = session.OpenContainer(L"demo-container", ProcessOutputMode::Event);
```
The method throws a projected exception with `Error::ContainerNotFound` if no container matches or
`Error::ContainerPrefixAmbiguous` if a partial ID is ambiguous.
## Session::PullImage(PullImageOptions)
Pulls an image synchronously.
```cpp
session.PullImage(PullImageOptions{ L"docker.io/library/alpine:latest" });
```
## Session::PullImageAsync(PullImageOptions)
Pulls an image asynchronously and reports progress.
```cpp
auto pullOp = session.PullImageAsync(PullImageOptions{ L"docker.io/library/alpine:latest" });
pullOp.Progress([](auto&&, ImageProgress const& progress)
{
printf("pull status: %d\n", static_cast<int>(progress.Status()));
});
co_await pullOp;
```
## Session::ImportImage(hstring, hstring)
Imports an image tarball synchronously from a file path.
```cpp
session.ImportImage(L"C:\\images\\alpine.tar", L"demo/alpine:latest");
```
## Session::ImportImageAsync(hstring, hstring)
Imports an image tarball asynchronously from a file path.
2026-06-26 17:28:07 -04:00
```cpp
auto importOp = session.ImportImageAsync(L"C:\\images\\alpine.tar", L"demo/alpine:latest");
importOp.Progress([](auto&&, ImageProgress const& p) { /* progress */ });
co_await importOp;
```
2026-09-29 07:14:54 -07:00
## Session::LoadImage(hstring)
Loads an image archive synchronously from a file path.
```cpp
session.LoadImage(L"C:\\images\\bundle.tar");
```
## Session::LoadImageAsync(hstring)
Loads an image archive asynchronously from a file path.
2026-06-26 17:28:07 -04:00
```cpp
auto loadOp = session.LoadImageAsync(L"C:\\images\\bundle.tar");
co_await loadOp;
```
2026-09-29 07:14:54 -07:00
## Session::PushImage(PushImageOptions)
Pushes an image synchronously to a registry.
```cpp
session.PushImage(pushOptions);
```
## Session::PushImageAsync(PushImageOptions)
Pushes an image asynchronously to a registry.
```cpp
co_await session.PushImageAsync(pushOptions);
```
## Session::DeleteImage(hstring)
Deletes an image by name or ID.
2026-06-26 17:28:07 -04:00
```cpp
session.DeleteImage(L"demo/alpine:latest");
```
2026-09-29 07:14:54 -07:00
## Session::TagImage(TagImageOptions)
Applies a new repository and tag to an existing image.
2026-06-26 17:28:07 -04:00
```cpp
2026-09-29 07:14:54 -07:00
session.TagImage(TagImageOptions{ L"alpine:latest", L"registry.example.com/alpine", L"v1" });
```
## Session::CreateVhdVolume(VhdOptions)
Creates a named session VHD volume.
```cpp
session.CreateVhdVolume(vhdOptions);
```
## Session::DeleteVhdVolume(hstring)
Deletes a named session VHD volume.
```cpp
session.DeleteVhdVolume(L"build-cache");
```
## Session::Authenticate(Uri, hstring, hstring)
Authenticates to a registry and returns registry authentication data suitable for
`PullImageOptions::RegistryAuth()` or `PushImageOptions::RegistryAuth()`.
```cpp
auto authentication = session.Authenticate(
2026-06-26 17:28:07 -04:00
winrt::Windows::Foundation::Uri{ L"https://registry.example.com" },
L"user",
L"password");
2026-09-29 07:14:54 -07:00
PullImageOptions authenticatedPull{ L"registry.example.com/demo:latest" };
authenticatedPull.RegistryAuth(authentication.IdentityToken());
session.PullImage(authenticatedPull);
2026-06-26 17:28:07 -04:00
```
2026-09-29 07:14:54 -07:00
## Session::GetImages()
Returns a snapshot of images known to the session.
2026-06-26 17:28:07 -04:00
```cpp
auto images = session.GetImages();
for (auto const& image : images)
{
printf("%ws\n", image.Name().c_str());
}
```
2026-09-29 07:14:54 -07:00
## Session::Terminated event
2026-06-26 17:28:07 -04:00
2026-09-29 07:14:54 -07:00
Raised when the session termination event is signaled.
2026-06-26 17:28:07 -04:00
```cpp
2026-09-29 07:14:54 -07:00
session.Terminated([](SessionTerminationReason reason)
{
printf("session terminated: %d\n", static_cast<int>(reason));
});
```
## Session::ProcessCrashed event
Raised when a process crash dump is reported.
```cpp
session.ProcessCrashed([](ProcessCrashInformation const& information)
{
printf("process crashed: %ws (%u)\n", information.ProcessName().c_str(), information.Pid());
});
```
## Session::Close()
Releases the underlying WinRT session object.
```cpp
session.Close();
2026-06-26 17:28:07 -04:00
```