Skip to content

Container

Represents a container inside a session.

public sealed class Container : IDisposable
{
    public string Id { get; }
    public Process InitProcess { get; }
    public ContainerState State { get; }

    public void Start();
    public void Stop(Signal signal, TimeSpan timeout);
    public void Delete(DeleteContainerOption option);
    public Process CreateProcess(ProcessSettings newProcessSettings);
    public string Inspect();
    public void Dispose();
}

Notes: - Start() has no flags parameter. - If InitProcess.OutputMode is Event or Stream, Start() automatically requests native attach. - InitProcess is only available when ContainerSettings.InitProcess was configured.

Container.Start()

Starts the container and, if configured, attaches the init process handle.

container.Start();

Container.Stop(Signal, TimeSpan)

Stops the container with a signal and timeout.

container.Stop(Signal.SIGTERM, TimeSpan.FromSeconds(10));

Container.Delete(DeleteContainerOption)

Deletes the container.

container.Delete(DeleteContainerOption.Force);

Container.CreateProcess(ProcessSettings)

Creates a secondary process object inside the container.

var execSettings = new ProcessSettings
{
    CommandLine = new List<string> { "/bin/sh", "-c", "echo secondary process" },
    OutputMode = ProcessOutputMode.Event
};

Process process = container.CreateProcess(execSettings);

Container.Inspect()

Returns the raw inspect payload as a string.

string inspectJson = container.Inspect();
Console.WriteLine(inspectJson);

Container.Id

Returns the container ID string.

Console.WriteLine(container.Id);

Container.InitProcess

Gets the configured init process object.

Process init = container.InitProcess;

Container.State

Gets the current container state.

Console.WriteLine(container.State);

Container.Dispose()

Releases the underlying WinRT container object.

container.Dispose();