@@ -45,6 +45,7 @@ import (
45
45
46
46
"github.com/containerd/nerdctl/v2/pkg/imgutil"
47
47
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/native"
48
+ "github.com/containerd/nerdctl/v2/pkg/ipcutil"
48
49
"github.com/containerd/nerdctl/v2/pkg/labels"
49
50
"github.com/containerd/nerdctl/v2/pkg/ocihook/state"
50
51
)
@@ -141,12 +142,15 @@ type Container struct {
141
142
// From https://github.com/moby/moby/blob/8dbd90ec00daa26dc45d7da2431c965dec99e8b4/api/types/container/host_config.go#L391
142
143
// HostConfig the non-portable Config structure of a container.
143
144
type HostConfig struct {
144
- ExtraHosts []string // List of extra hosts
145
- PortBindings nat.PortMap // Port mapping between the exposed port (container) and the host
146
- LogConfig LogConfig // Configuration of the logs for this container
147
- BlkioWeight uint16 // Block IO weight (relative weight vs. other containers)
148
- CpusetMems string // CpusetMems 0-2, 0,1
149
- CpusetCpus string // CpusetCpus 0-2, 0,1
145
+ ExtraHosts []string // List of extra hosts
146
+ PortBindings nat.PortMap // Port mapping between the exposed port (container) and the host
147
+ LogConfig LogConfig // Configuration of the logs for this container
148
+ BlkioWeight uint16 // Block IO weight (relative weight vs. other containers)
149
+ CpusetMems string // CpusetMems 0-2, 0,1
150
+ CpusetCpus string // CpusetCpus 0-2, 0,1
151
+ ContainerIDFile string // File (path) where the containerId is written
152
+ GroupAdd []string // GroupAdd specifies additional groups to join
153
+ IpcMode string // IPC namespace to use for the container
150
154
}
151
155
152
156
// From https://github.com/moby/moby/blob/v20.10.1/api/types/types.go#L416-L427
@@ -347,6 +351,22 @@ func ContainerFromNative(n *native.Container) (*Container, error) {
347
351
c .HostConfig .CpusetCpus = cpusetcpus
348
352
}
349
353
354
+ if cidFile := n .Labels [labels .CIdFile ]; cidFile != "" {
355
+ c .HostConfig .ContainerIDFile = cidFile
356
+ }
357
+
358
+ if groupAdd := n .Labels [labels .GroupAdd ]; groupAdd != "" {
359
+ c .HostConfig .GroupAdd = parseGroups (groupAdd )
360
+ }
361
+
362
+ if ipcMode := n .Labels [labels .IPC ]; ipcMode != "" {
363
+ ipc , err := ipcutil .DecodeIPCLabel (ipcMode )
364
+ if err != nil {
365
+ return nil , fmt .Errorf ("failed to Decode IPC Label: %v" , err )
366
+ }
367
+ c .HostConfig .IpcMode = string (ipc .Mode )
368
+ }
369
+
350
370
cs := new (ContainerState )
351
371
cs .Restarting = n .Labels [restart .StatusLabel ] == string (containerd .Running )
352
372
cs .Error = n .Labels [labels .Error ]
@@ -568,6 +588,14 @@ func parseExtraHosts(extraHostsJSON string) []string {
568
588
return extraHosts
569
589
}
570
590
591
+ func parseGroups (groupAddJSON string ) []string {
592
+ var groupAdd []string
593
+ if err := json .Unmarshal ([]byte (groupAddJSON ), & groupAdd ); err != nil {
594
+ return []string {}
595
+ }
596
+ return groupAdd
597
+ }
598
+
571
599
type IPAMConfig struct {
572
600
Subnet string `json:"Subnet,omitempty"`
573
601
Gateway string `json:"Gateway,omitempty"`
0 commit comments