mirror of
https://github.com/yusing/godoxy.git
synced 2025-07-01 04:54:26 +02:00
feat(container): add UpdatePorts method and support for host network mode
This commit is contained in:
parent
9eb674029e
commit
c90ec8caa1
2 changed files with 44 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -37,10 +38,11 @@ type (
|
|||
PublicHostname string `json:"public_hostname"`
|
||||
PrivateHostname string `json:"private_hostname"`
|
||||
|
||||
Aliases []string `json:"aliases"`
|
||||
IsExcluded bool `json:"is_excluded"`
|
||||
IsExplicit bool `json:"is_explicit"`
|
||||
Running bool `json:"running"`
|
||||
Aliases []string `json:"aliases"`
|
||||
IsExcluded bool `json:"is_excluded"`
|
||||
IsExplicit bool `json:"is_explicit"`
|
||||
IsHostNetworkMode bool `json:"is_host_network_mode"`
|
||||
Running bool `json:"running"`
|
||||
}
|
||||
ContainerImage struct {
|
||||
Author string `json:"author,omitempty"`
|
||||
|
@ -76,10 +78,11 @@ func FromDocker(c *container.SummaryTrimmed, dockerHost string) (res *Container)
|
|||
PublicPortMapping: helper.getPublicPortMapping(),
|
||||
PrivatePortMapping: helper.getPrivatePortMapping(),
|
||||
|
||||
Aliases: helper.getAliases(),
|
||||
IsExcluded: isExcluded,
|
||||
IsExplicit: isExplicit,
|
||||
Running: c.Status == "running" || c.State == "running",
|
||||
Aliases: helper.getAliases(),
|
||||
IsExcluded: isExcluded,
|
||||
IsExplicit: isExplicit,
|
||||
IsHostNetworkMode: c.HostConfig.NetworkMode == "host",
|
||||
Running: c.Status == "running" || c.State == "running",
|
||||
}
|
||||
|
||||
if agent.IsDockerHostAgent(dockerHost) {
|
||||
|
@ -201,3 +204,28 @@ func (c *Container) loadDeleteIdlewatcherLabels(helper containerHelper) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Container) UpdatePorts() error {
|
||||
client, err := NewClient(c.DockerHost)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
inspect, err := client.ContainerInspect(context.Background(), c.ContainerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for port := range inspect.Config.ExposedPorts {
|
||||
if port.Int() == 0 {
|
||||
continue
|
||||
}
|
||||
c.PublicPortMapping[port.Int()] = container.Port{
|
||||
PublicPort: uint16(port.Int()),
|
||||
PrivatePort: uint16(port.Int()),
|
||||
Type: port.Proto(),
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -75,6 +75,14 @@ func (p *DockerProvider) loadRoutesImpl() (route.Routes, gperr.Error) {
|
|||
continue
|
||||
}
|
||||
|
||||
if container.IsHostNetworkMode {
|
||||
err := container.UpdatePorts()
|
||||
if err != nil {
|
||||
errs.Add(gperr.PrependSubject(container.ContainerName, err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
newEntries, err := p.routesFromContainerLabels(container)
|
||||
if err != nil {
|
||||
errs.Add(err.Subject(container.ContainerName))
|
||||
|
|
Loading…
Add table
Reference in a new issue