1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Decouple daemon and container to cleanup containers.

Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
David Calavera 2015-11-03 12:43:36 -05:00
parent ca5ede2d0a
commit 019c337b93
5 changed files with 26 additions and 23 deletions

View file

@ -236,24 +236,6 @@ func (streamConfig *streamConfig) StderrPipe() io.ReadCloser {
return ioutils.NewBufReader(reader) 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 // ExitOnNext signals to the monitor that it should not restart the container
// after we send the kill signal. // after we send the kill signal.
func (container *Container) ExitOnNext() { func (container *Container) ExitOnNext() {

View file

@ -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 { if container.hostConfig.NetworkMode.IsContainer() || container.Config.NetworkDisabled {
return return
} }
@ -1170,7 +1170,7 @@ func (container *Container) releaseNetwork() {
return return
} }
sb, err := container.daemon.netController.SandboxByID(sid) sb, err := daemon.netController.SandboxByID(sid)
if err != nil { if err != nil {
logrus.Errorf("error locating sandbox id %s: %v", sid, err) logrus.Errorf("error locating sandbox id %s: %v", sid, err)
return return

View file

@ -162,7 +162,7 @@ func (container *Container) updateNetwork() error {
return nil 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. // appendNetworkMounts appends any network mounts to the array of mount points passed in.

View file

@ -21,6 +21,8 @@ const (
type containerSupervisor interface { type containerSupervisor interface {
// LogContainerEvent generates events related to a given container // LogContainerEvent generates events related to a given container
LogContainerEvent(*Container, string) LogContainerEvent(*Container, string)
// Cleanup ensures that the container is properly unmounted
Cleanup(*Container)
} }
// containerMonitor monitors the execution of a container's main process. // containerMonitor monitors the execution of a container's main process.
@ -96,7 +98,7 @@ func (m *containerMonitor) ExitOnNext() {
// unmounts the contatiner's root filesystem // unmounts the contatiner's root filesystem
func (m *containerMonitor) Close() error { func (m *containerMonitor) Close() error {
// Cleanup networking and mounts // Cleanup networking and mounts
m.container.cleanup() m.supervisor.Cleanup(m.container)
// FIXME: here is race condition between two RUN instructions in Dockerfile // FIXME: here is race condition between two RUN instructions in Dockerfile
// because they share same runconfig and change image. Must be fixed // because they share same runconfig and change image. Must be fixed

View file

@ -3,6 +3,7 @@ package daemon
import ( import (
"runtime" "runtime"
"github.com/Sirupsen/logrus"
derr "github.com/docker/docker/errors" derr "github.com/docker/docker/errors"
"github.com/docker/docker/pkg/promise" "github.com/docker/docker/pkg/promise"
"github.com/docker/docker/runconfig" "github.com/docker/docker/runconfig"
@ -83,7 +84,7 @@ func (daemon *Daemon) containerStart(container *Container) (err error) {
container.ExitCode = 128 container.ExitCode = 128
} }
container.toDisk() container.toDisk()
container.cleanup() daemon.Cleanup(container)
daemon.LogContainerEvent(container, "die") daemon.LogContainerEvent(container, "die")
} }
}() }()
@ -140,3 +141,21 @@ func (daemon *Daemon) waitForStart(container *Container) error {
return nil 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)
}
}