mirror of
https://gitea.elkins.co/Networking/ccl.git
synced 2025-02-04 12:02:47 -06:00
Add port mapping and netns container fields
This commit is contained in:
parent
793e87043c
commit
be88a1700b
@ -54,6 +54,8 @@ type Container struct {
|
|||||||
User string `toml:"user,omitempty"`
|
User string `toml:"user,omitempty"`
|
||||||
ExposeTcp []uint16 `toml:"expose_tcp,omitempty"`
|
ExposeTcp []uint16 `toml:"expose_tcp,omitempty"`
|
||||||
ExposeUdp []uint16 `toml:"expose_udp,omitempty"`
|
ExposeUdp []uint16 `toml:"expose_udp,omitempty"`
|
||||||
|
PortsTcp map[uint16]uint16 `toml:"ports,omitempty"`
|
||||||
|
NetNS string `toml:"netns,omitempty"`
|
||||||
|
|
||||||
conn context.Context
|
conn context.Context
|
||||||
cdata *define.InspectContainerData
|
cdata *define.InspectContainerData
|
||||||
@ -91,6 +93,11 @@ func (c *Container) Init(conn context.Context, nets []network.Network) error {
|
|||||||
if !c.Umask.Valid {
|
if !c.Umask.Valid {
|
||||||
c.Umask.SetValid(0o022)
|
c.Umask.SetValid(0o022)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.NetNS == "" {
|
||||||
|
c.NetNS = string(specgen.Bridge)
|
||||||
|
}
|
||||||
|
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return fmt.Errorf("conn is nil: %s", c.Name)
|
return fmt.Errorf("conn is nil: %s", c.Name)
|
||||||
}
|
}
|
||||||
@ -168,6 +175,15 @@ func (c *Container) CreateCommands() cmd.CommandSet {
|
|||||||
expose[p] = "udp"
|
expose[p] = "udp"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
portMappings := []types.PortMapping{}
|
||||||
|
for ph, pc := range c.PortsTcp {
|
||||||
|
portMappings = append(portMappings, types.PortMapping{
|
||||||
|
HostPort: ph,
|
||||||
|
ContainerPort: pc,
|
||||||
|
Protocol: "tcp",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
spec := specgen.SpecGenerator{
|
spec := specgen.SpecGenerator{
|
||||||
ContainerBasicConfig: specgen.ContainerBasicConfig{
|
ContainerBasicConfig: specgen.ContainerBasicConfig{
|
||||||
Name: c.Name,
|
Name: c.Name,
|
||||||
@ -187,7 +203,9 @@ func (c *Container) CreateCommands() cmd.CommandSet {
|
|||||||
Networks: nets,
|
Networks: nets,
|
||||||
DNSServers: dns,
|
DNSServers: dns,
|
||||||
Expose: expose,
|
Expose: expose,
|
||||||
|
PortMappings: portMappings,
|
||||||
PublishExposedPorts: len(expose) > 0,
|
PublishExposedPorts: len(expose) > 0,
|
||||||
|
NetNS: specgen.Namespace{NSMode: specgen.NamespaceMode(c.NetNS)},
|
||||||
},
|
},
|
||||||
ContainerSecurityConfig: specgen.ContainerSecurityConfig{
|
ContainerSecurityConfig: specgen.ContainerSecurityConfig{
|
||||||
User: c.User,
|
User: c.User,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user