4f0d95fa |
package daemon // import "github.com/docker/docker/daemon" |
c7cfdb65 |
|
0a734182 |
import ( |
ddae20c0 |
"context" |
a793564b |
"fmt"
|
6bb0d181 |
"github.com/docker/docker/container" |
ddae20c0 |
"github.com/sirupsen/logrus" |
0a734182 |
) |
c7cfdb65 |
// ContainerPause pauses a container |
b08f071e |
func (daemon *Daemon) ContainerPause(name string) error { |
d7d512bb |
container, err := daemon.GetContainer(name) |
c7cfdb65 |
if err != nil {
return err
} |
b4a63139 |
return daemon.containerPause(container) |
c7cfdb65 |
} |
9f79cfdb |
// containerPause pauses the container execution without stopping the process.
// The execution can be resumed by calling containerUnpause. |
6bb0d181 |
func (daemon *Daemon) containerPause(container *container.Container) error { |
9f79cfdb |
container.Lock()
defer container.Unlock()
// We cannot Pause the container which is not running
if !container.Running { |
ebcb7d6b |
return errNotRunning(container.ID) |
9f79cfdb |
}
// We cannot Pause the container which is already paused
if container.Paused { |
ddae20c0 |
return errNotPaused(container.ID) |
9f79cfdb |
}
|
2c63ac3a |
// We cannot Pause the container which is restarting
if container.Restarting { |
a793564b |
return errContainerIsRestarting(container.ID) |
2c63ac3a |
}
|
ddae20c0 |
if err := daemon.containerd.Pause(context.Background(), container.ID); err != nil { |
a793564b |
return fmt.Errorf("Cannot pause container %s: %s", container.ID, err) |
9f79cfdb |
} |
9c4570a9 |
|
ddae20c0 |
container.Paused = true
daemon.setStateCounter(container)
daemon.updateHealthMonitor(container)
daemon.LogContainerEvent(container, "pause")
if err := container.CheckpointTo(daemon.containersReplica); err != nil {
logrus.WithError(err).Warn("could not save container to disk")
}
|
9f79cfdb |
return nil
} |