@@ -45,6 +45,7 @@ import (
4545
4646 "github.com/containerd/nerdctl/v2/pkg/imgutil"
4747 "github.com/containerd/nerdctl/v2/pkg/inspecttypes/native"
48+ "github.com/containerd/nerdctl/v2/pkg/ipcutil"
4849 "github.com/containerd/nerdctl/v2/pkg/labels"
4950 "github.com/containerd/nerdctl/v2/pkg/ocihook/state"
5051)
@@ -141,12 +142,15 @@ type Container struct {
141142// From https://github.com/moby/moby/blob/8dbd90ec00daa26dc45d7da2431c965dec99e8b4/api/types/container/host_config.go#L391
142143// HostConfig the non-portable Config structure of a container.
143144type 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
150154}
151155
152156// 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) {
347351 c .HostConfig .CpusetCpus = cpusetcpus
348352 }
349353
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+
350370 cs := new (ContainerState )
351371 cs .Restarting = n .Labels [restart .StatusLabel ] == string (containerd .Running )
352372 cs .Error = n .Labels [labels .Error ]
@@ -566,6 +586,14 @@ func parseExtraHosts(extraHostsJSON string) []string {
566586 return extraHosts
567587}
568588
589+ func parseGroups (groupAddJSON string ) []string {
590+ var groupAdd []string
591+ if err := json .Unmarshal ([]byte (groupAddJSON ), & groupAdd ); err != nil {
592+ return []string {}
593+ }
594+ return groupAdd
595+ }
596+
569597type IPAMConfig struct {
570598 Subnet string `json:"Subnet,omitempty"`
571599 Gateway string `json:"Gateway,omitempty"`
0 commit comments