From f624d6187a8daa3ca0999c46cb345f8db6f330e7 Mon Sep 17 00:00:00 2001 From: Burke Libbey Date: Tue, 13 Oct 2015 17:46:55 -0400 Subject: [PATCH 1/3] Fix --ipc=host dependency on /dev/mqueue existing Since #15862, containers fail to start when started with --ipc=host if /dev/mqueue is not present. This change causes docker to create container-local mounts for --ipc=host containers as well as in the default case. Signed-off-by: Burke Libbey --- daemon/container.go | 2 +- daemon/container_unix.go | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/daemon/container.go b/daemon/container.go index 53807f90e6..b31c40bd88 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -288,7 +288,7 @@ func (container *Container) Start() (err error) { return err } - if !container.hostConfig.IpcMode.IsContainer() && !container.hostConfig.IpcMode.IsHost() { + if !container.hostConfig.IpcMode.IsContainer() { if err := container.setupIpcDirs(); err != nil { return err } diff --git a/daemon/container_unix.go b/daemon/container_unix.go index a31fde6f78..b6ed72b923 100644 --- a/daemon/container_unix.go +++ b/daemon/container_unix.go @@ -214,12 +214,6 @@ func populateCommand(c *Container, env []string) error { ipc.ContainerID = ic.ID c.ShmPath = ic.ShmPath c.MqueuePath = ic.MqueuePath - } else { - ipc.HostIpc = c.hostConfig.IpcMode.IsHost() - if ipc.HostIpc { - c.ShmPath = "/dev/shm" - c.MqueuePath = "/dev/mqueue" - } } pid := &execdriver.Pid{} @@ -1408,7 +1402,7 @@ func (container *Container) setupIpcDirs() error { } func (container *Container) unmountIpcMounts() error { - if container.hostConfig.IpcMode.IsContainer() || container.hostConfig.IpcMode.IsHost() { + if container.hostConfig.IpcMode.IsContainer() { return nil } From ab7923558d61caccafd08aee667e7fc44a80164e Mon Sep 17 00:00:00 2001 From: Burke Libbey Date: Wed, 14 Oct 2015 10:45:57 -0400 Subject: [PATCH 2/3] Revert "Fix --ipc=host dependency on /dev/mqueue existing" This reverts commit f624d6187a8daa3ca0999c46cb345f8db6f330e7. Signed-off-by: Burke Libbey --- daemon/container.go | 2 +- daemon/container_unix.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/daemon/container.go b/daemon/container.go index b31c40bd88..53807f90e6 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -288,7 +288,7 @@ func (container *Container) Start() (err error) { return err } - if !container.hostConfig.IpcMode.IsContainer() { + if !container.hostConfig.IpcMode.IsContainer() && !container.hostConfig.IpcMode.IsHost() { if err := container.setupIpcDirs(); err != nil { return err } diff --git a/daemon/container_unix.go b/daemon/container_unix.go index b6ed72b923..a31fde6f78 100644 --- a/daemon/container_unix.go +++ b/daemon/container_unix.go @@ -214,6 +214,12 @@ func populateCommand(c *Container, env []string) error { ipc.ContainerID = ic.ID c.ShmPath = ic.ShmPath c.MqueuePath = ic.MqueuePath + } else { + ipc.HostIpc = c.hostConfig.IpcMode.IsHost() + if ipc.HostIpc { + c.ShmPath = "/dev/shm" + c.MqueuePath = "/dev/mqueue" + } } pid := &execdriver.Pid{} @@ -1402,7 +1408,7 @@ func (container *Container) setupIpcDirs() error { } func (container *Container) unmountIpcMounts() error { - if container.hostConfig.IpcMode.IsContainer() { + if container.hostConfig.IpcMode.IsContainer() || container.hostConfig.IpcMode.IsHost() { return nil } From fd955ce6ca7c8659d76de5dc397b307a3a22e2c4 Mon Sep 17 00:00:00 2001 From: Burke Libbey Date: Wed, 14 Oct 2015 10:50:43 -0400 Subject: [PATCH 3/3] Better error when --host=ipc but no /dev/mqueue Signed-off-by: Burke Libbey --- daemon/container_unix.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/daemon/container_unix.go b/daemon/container_unix.go index a31fde6f78..b8b3d7d572 100644 --- a/daemon/container_unix.go +++ b/daemon/container_unix.go @@ -217,6 +217,12 @@ func populateCommand(c *Container, env []string) error { } else { ipc.HostIpc = c.hostConfig.IpcMode.IsHost() if ipc.HostIpc { + if _, err := os.Stat("/dev/shm"); err != nil { + return fmt.Errorf("/dev/shm is not mounted, but must be for --host=ipc") + } + if _, err := os.Stat("/dev/mqueue"); err != nil { + return fmt.Errorf("/dev/mqueue is not mounted, but must be for --host=ipc") + } c.ShmPath = "/dev/shm" c.MqueuePath = "/dev/mqueue" }