| 1 | # ContainerSettings |
| 2 | |
| 3 | Configures a container before creation. |
| 4 | |
| 5 | ```csharp |
| 6 | public sealed class ContainerSettings |
| 7 | { |
| 8 | public ContainerSettings(string imageName); |
| 9 | |
| 10 | public string ImageName { get; set; } |
| 11 | public string Name { get; set; } |
| 12 | public ProcessSettings InitProcess { get; set; } |
| 13 | public ContainerNetworkingMode? NetworkingMode { get; set; } |
| 14 | public string HostName { get; set; } |
| 15 | public string DomainName { get; set; } |
| 16 | public bool EnableAutoRemove { get; set; } |
| 17 | public bool EnableGpu { get; set; } |
| 18 | public bool Privileged { get; set; } |
| 19 | public IList<ContainerPortMapping> PortMappings { get; set; } |
| 20 | public IList<ContainerVolume> Volumes { get; set; } |
| 21 | public IList<ContainerNamedVolume> NamedVolumes { get; set; } |
| 22 | } |
| 23 | ``` |
| 24 | |
| 25 | Notes: |
| 26 | |
| 27 | - `PortMappings`, `Volumes`, and `NamedVolumes` are mutable collections. |
| 28 | - `InitProcess` is optional. |
| 29 | - `NetworkingMode` is nullable; `null` means “leave default behavior”. |
| 30 | |
| 31 | Example: |
| 32 | |
| 33 | ```csharp |
| 34 | var init = new ProcessSettings |
| 35 | { |
| 36 | CommandLine = new List<string> { "/bin/sh", "-c", "echo hello from init" }, |
| 37 | OutputMode = ProcessOutputMode.Event |
| 38 | }; |
| 39 | |
| 40 | var containerSettings = new ContainerSettings("docker.io/library/alpine:latest") |
| 41 | { |
| 42 | Name = "demo-container", |
| 43 | InitProcess = init, |
| 44 | NetworkingMode = ContainerNetworkingMode.Bridged, |
| 45 | EnableAutoRemove = true, |
| 46 | PortMappings = new List<ContainerPortMapping> |
| 47 | { |
| 48 | new(8080, 80, PortProtocol.TCP) |
| 49 | }, |
| 50 | Volumes = new List<ContainerVolume> |
| 51 | { |
| 52 | new(@"C:\data", "/workspace/data", false) |
| 53 | }, |
| 54 | NamedVolumes = new List<ContainerNamedVolume> |
| 55 | { |
| 56 | new("cache", "/var/cache/app", false) |
| 57 | } |
| 58 | }; |
| 59 | ``` |