summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libpod/container_internal_linux.go23
-rw-r--r--libpod/runtime_pod_infra_linux.go44
2 files changed, 46 insertions, 21 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index f50092550..c9f35dd75 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -665,18 +665,21 @@ func (c *Container) makeBindMounts() error {
if !netDisabled {
// If /etc/resolv.conf and /etc/hosts exist, delete them so we
- // will recreate
- if path, ok := c.state.BindMounts["/etc/resolv.conf"]; ok {
- if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
- return errors.Wrapf(err, "error removing container %s resolv.conf", c.ID())
+ // will recreate. Only do this if we aren't sharing them with
+ // another container.
+ if c.config.NetNsCtr == "" {
+ if path, ok := c.state.BindMounts["/etc/resolv.conf"]; ok {
+ if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
+ return errors.Wrapf(err, "error removing container %s resolv.conf", c.ID())
+ }
+ delete(c.state.BindMounts, "/etc/resolv.conf")
}
- delete(c.state.BindMounts, "/etc/resolv.conf")
- }
- if path, ok := c.state.BindMounts["/etc/hosts"]; ok {
- if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
- return errors.Wrapf(err, "error removing container %s hosts", c.ID())
+ if path, ok := c.state.BindMounts["/etc/hosts"]; ok {
+ if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
+ return errors.Wrapf(err, "error removing container %s hosts", c.ID())
+ }
+ delete(c.state.BindMounts, "/etc/hosts")
}
- delete(c.state.BindMounts, "/etc/hosts")
}
if c.config.NetNsCtr != "" {
diff --git a/libpod/runtime_pod_infra_linux.go b/libpod/runtime_pod_infra_linux.go
index 81579db4b..0a5f78cf8 100644
--- a/libpod/runtime_pod_infra_linux.go
+++ b/libpod/runtime_pod_infra_linux.go
@@ -12,6 +12,7 @@ import (
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/generate"
"github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
)
const (
@@ -31,23 +32,44 @@ func (r *Runtime) makeInfraContainer(ctx context.Context, p *Pod, imgName, imgID
isRootless := rootless.IsRootless()
entryCmd := []string{r.config.InfraCommand}
- // default to entrypoint in image if there is one
- if len(config.Entrypoint) > 0 {
- entryCmd = config.Entrypoint
- }
- if len(config.Env) > 0 {
- for _, nameValPair := range config.Env {
- nameValSlice := strings.Split(nameValPair, "=")
- if len(nameValSlice) < 2 {
- return nil, errors.Errorf("Invalid environment variable structure in pause image")
+ // I've seen circumstances where config is being passed as nil.
+ // Let's err on the side of safety and make sure it's safe to use.
+ if config != nil {
+ setEntrypoint := false
+ // default to entrypoint in image if there is one
+ if len(config.Entrypoint) > 0 {
+ entryCmd = config.Entrypoint
+ setEntrypoint = true
+ }
+ if len(config.Cmd) > 0 {
+ // We can't use the default pause command, since we're
+ // sourcing from the image. If we didn't already set an
+ // entrypoint, set one now.
+ if !setEntrypoint {
+ // Use the Docker default "/bin/sh -c"
+ // entrypoint, as we're overriding command.
+ // If an image doesn't want this, it can
+ // override entrypoint too.
+ entryCmd = []string{"/bin/sh", "-c"}
+ }
+ entryCmd = append(entryCmd, config.Cmd...)
+ }
+ if len(config.Env) > 0 {
+ for _, nameValPair := range config.Env {
+ nameValSlice := strings.Split(nameValPair, "=")
+ if len(nameValSlice) < 2 {
+ return nil, errors.Errorf("Invalid environment variable structure in pause image")
+ }
+ g.AddProcessEnv(nameValSlice[0], nameValSlice[1])
}
- g.AddProcessEnv(nameValSlice[0], nameValSlice[1])
}
}
g.SetRootReadonly(true)
g.SetProcessArgs(entryCmd)
+ logrus.Debugf("Using %q as infra container entrypoint", entryCmd)
+
if isRootless {
g.RemoveMount("/dev/pts")
devPts := spec.Mount{
@@ -97,5 +119,5 @@ func (r *Runtime) createInfraContainer(ctx context.Context, p *Pod) (*Container,
imageName := newImage.Names()[0]
imageID := data.ID
- return r.makeInfraContainer(ctx, p, imageName, imageID, newImage.Config)
+ return r.makeInfraContainer(ctx, p, imageName, imageID, data.Config)
}