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:
parent
ca5ede2d0a
commit
019c337b93
5 changed files with 26 additions and 23 deletions
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue