diff --git a/daemon/container.go b/daemon/container.go index 8a5b0fd266..87b0e009da 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -236,24 +236,6 @@ func (streamConfig *streamConfig) StderrPipe() io.ReadCloser { return ioutils.NewBufReader(reader) } -// cleanup releases any network resources allocated to the container along with any rules -// around how containers are linked together. It also unmounts the container's root filesystem. -func (container *Container) cleanup() { - container.releaseNetwork() - - container.unmountIpcMounts(detachMounted) - - container.daemon.conditionalUnmountOnCleanup(container) - - for _, eConfig := range container.execCommands.s { - container.daemon.unregisterExecCommand(eConfig) - } - - if err := container.unmountVolumes(false); err != nil { - logrus.Warnf("%s cleanup: Failed to umount volumes: %v", container.ID, err) - } -} - // ExitOnNext signals to the monitor that it should not restart the container // after we send the kill signal. func (container *Container) ExitOnNext() { diff --git a/daemon/container_unix.go b/daemon/container_unix.go index 8cd8989f6d..640bf5bcb2 100644 --- a/daemon/container_unix.go +++ b/daemon/container_unix.go @@ -1153,7 +1153,7 @@ func (container *Container) getNetworkedContainer() (*Container, error) { } } -func (container *Container) releaseNetwork() { +func (daemon *Daemon) releaseNetwork(container *Container) { if container.hostConfig.NetworkMode.IsContainer() || container.Config.NetworkDisabled { return } @@ -1170,7 +1170,7 @@ func (container *Container) releaseNetwork() { return } - sb, err := container.daemon.netController.SandboxByID(sid) + sb, err := daemon.netController.SandboxByID(sid) if err != nil { logrus.Errorf("error locating sandbox id %s: %v", sid, err) return diff --git a/daemon/container_windows.go b/daemon/container_windows.go index f618cd8c23..0ad1fc69ad 100644 --- a/daemon/container_windows.go +++ b/daemon/container_windows.go @@ -162,7 +162,7 @@ func (container *Container) updateNetwork() error { return nil } -func (container *Container) releaseNetwork() { +func (daemon *Daemon) releaseNetwork(container *Container) { } // appendNetworkMounts appends any network mounts to the array of mount points passed in. diff --git a/daemon/monitor.go b/daemon/monitor.go index 4a24b7d94b..3512cbd1cd 100644 --- a/daemon/monitor.go +++ b/daemon/monitor.go @@ -21,6 +21,8 @@ const ( type containerSupervisor interface { // LogContainerEvent generates events related to a given container LogContainerEvent(*Container, string) + // Cleanup ensures that the container is properly unmounted + Cleanup(*Container) } // containerMonitor monitors the execution of a container's main process. @@ -96,7 +98,7 @@ func (m *containerMonitor) ExitOnNext() { // unmounts the contatiner's root filesystem func (m *containerMonitor) Close() error { // Cleanup networking and mounts - m.container.cleanup() + m.supervisor.Cleanup(m.container) // FIXME: here is race condition between two RUN instructions in Dockerfile // because they share same runconfig and change image. Must be fixed diff --git a/daemon/start.go b/daemon/start.go index de86b9e476..89a6020f41 100644 --- a/daemon/start.go +++ b/daemon/start.go @@ -3,6 +3,7 @@ package daemon import ( "runtime" + "github.com/Sirupsen/logrus" derr "github.com/docker/docker/errors" "github.com/docker/docker/pkg/promise" "github.com/docker/docker/runconfig" @@ -83,7 +84,7 @@ func (daemon *Daemon) containerStart(container *Container) (err error) { container.ExitCode = 128 } container.toDisk() - container.cleanup() + daemon.Cleanup(container) daemon.LogContainerEvent(container, "die") } }() @@ -140,3 +141,21 @@ func (daemon *Daemon) waitForStart(container *Container) error { return nil } + +// Cleanup releases any network resources allocated to the container along with any rules +// around how containers are linked together. It also unmounts the container's root filesystem. +func (daemon *Daemon) Cleanup(container *Container) { + daemon.releaseNetwork(container) + + container.unmountIpcMounts(detachMounted) + + daemon.conditionalUnmountOnCleanup(container) + + for _, eConfig := range container.execCommands.s { + daemon.unregisterExecCommand(eConfig) + } + + if err := container.unmountVolumes(false); err != nil { + logrus.Warnf("%s cleanup: Failed to umount volumes: %v", container.ID, err) + } +}