summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_internal_linux.go51
-rw-r--r--libpod/runtime.go3
-rw-r--r--libpod/runtime_ctr.go33
3 files changed, 68 insertions, 19 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index 7745646b6..28d961e4b 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -2221,33 +2221,50 @@ func (c *Container) getHosts() string {
depCtr = c
}
+ // getLocalIP returns the non loopback local IP of the host
+ getLocalIP := func() string {
+ addrs, err := net.InterfaceAddrs()
+ if err != nil {
+ return ""
+ }
+ for _, address := range addrs {
+ // check the address type and if it is not a loopback the display it
+ if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
+ if ipnet.IP.To4() != nil {
+ return ipnet.IP.String()
+ }
+ }
+ }
+ return ""
+ }
+
if depCtr != nil {
- for _, status := range depCtr.getNetworkStatus() {
+ host := ""
+ outer:
+ for net, status := range depCtr.getNetworkStatus() {
+ network, err := c.runtime.network.NetworkInspect(net)
+ // only add the host entry for bridge networks
+ // ip/macvlan gateway is normally not on the host
+ if err != nil || network.Driver != types.BridgeNetworkDriver {
+ continue
+ }
for _, netInt := range status.Interfaces {
for _, netAddress := range netInt.Subnets {
if netAddress.Gateway != nil {
- hosts += fmt.Sprintf("%s host.containers.internal\n", netAddress.Gateway.String())
+ host = fmt.Sprintf("%s host.containers.internal\n", netAddress.Gateway.String())
+ break outer
}
}
}
}
- } else if c.config.NetMode.IsSlirp4netns() {
- // getLocalIP returns the non loopback local IP of the host
- getLocalIP := func() string {
- addrs, err := net.InterfaceAddrs()
- if err != nil {
- return ""
- }
- for _, address := range addrs {
- // check the address type and if it is not a loopback the display it
- if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
- if ipnet.IP.To4() != nil {
- return ipnet.IP.String()
- }
- }
+ // if no bridge gw was found try to use a local ip
+ if host == "" {
+ if ip := getLocalIP(); ip != "" {
+ host = fmt.Sprintf("%s\t%s\n", ip, "host.containers.internal")
}
- return ""
}
+ hosts += host
+ } else if c.config.NetMode.IsSlirp4netns() {
if ip := getLocalIP(); ip != "" {
hosts += fmt.Sprintf("%s\t%s\n", ip, "host.containers.internal")
}
diff --git a/libpod/runtime.go b/libpod/runtime.go
index 9794b3605..3297b1ddd 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -170,7 +170,6 @@ func NewRuntime(ctx context.Context, options ...RuntimeOption) (*Runtime, error)
if err != nil {
return nil, err
}
- conf.CheckCgroupsAndAdjustConfig()
return newRuntimeFromConfig(ctx, conf, options...)
}
@@ -228,6 +227,8 @@ func newRuntimeFromConfig(ctx context.Context, conf *config.Config, options ...R
return nil, err
}
+ runtime.config.CheckCgroupsAndAdjustConfig()
+
return runtime, nil
}
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go
index 59a1fd153..53ccb9139 100644
--- a/libpod/runtime_ctr.go
+++ b/libpod/runtime_ctr.go
@@ -429,7 +429,7 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai
}()
ctr.config.SecretsPath = filepath.Join(ctr.config.StaticDir, "secrets")
- err = os.MkdirAll(ctr.config.SecretsPath, 0644)
+ err = os.MkdirAll(ctr.config.SecretsPath, 0755)
if err != nil {
return nil, err
}
@@ -915,6 +915,37 @@ func (r *Runtime) evictContainer(ctx context.Context, idOrName string, removeVol
return id, cleanupErr
}
+// RemoveDepend removes all dependencies for a container
+func (r *Runtime) RemoveDepend(ctx context.Context, rmCtr *Container, force bool, removeVolume bool, timeout *uint) ([]*reports.RmReport, error) {
+ rmReports := make([]*reports.RmReport, 0)
+ deps, err := r.state.ContainerInUse(rmCtr)
+ if err != nil {
+ if err == define.ErrCtrRemoved {
+ return rmReports, nil
+ }
+ return rmReports, err
+ }
+ for _, cid := range deps {
+ ctr, err := r.state.Container(cid)
+ if err != nil {
+ if err == define.ErrNoSuchCtr {
+ continue
+ }
+ return rmReports, err
+ }
+
+ reports, err := r.RemoveDepend(ctx, ctr, force, removeVolume, timeout)
+ if err != nil {
+ return rmReports, err
+ }
+ rmReports = append(rmReports, reports...)
+ }
+ report := reports.RmReport{Id: rmCtr.ID()}
+ report.Err = r.removeContainer(ctx, rmCtr, force, removeVolume, false, timeout)
+
+ return append(rmReports, &report), nil
+}
+
// GetContainer retrieves a container by its ID
func (r *Runtime) GetContainer(id string) (*Container, error) {
r.lock.RLock()