c7cfdb65 |
package daemon
|
0a734182 |
import ( |
a793564b |
"fmt"
|
6bb0d181 |
"github.com/docker/docker/container" |
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
}
|
9f79cfdb |
if err := daemon.containerPause(container); err != nil { |
894266c1 |
return err |
c7cfdb65 |
}
return nil
} |
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 { |
a793564b |
return errNotRunning{container.ID} |
9f79cfdb |
}
// We cannot Pause the container which is already paused
if container.Paused { |
a793564b |
return fmt.Errorf("Container %s is already paused", container.ID) |
9f79cfdb |
}
|
2c63ac3a |
// We cannot Pause the container which is restarting
if container.Restarting { |
a793564b |
return errContainerIsRestarting(container.ID) |
2c63ac3a |
}
|
9c4570a9 |
if err := daemon.containerd.Pause(container.ID); err != nil { |
a793564b |
return fmt.Errorf("Cannot pause container %s: %s", container.ID, err) |
9f79cfdb |
} |
9c4570a9 |
|
9f79cfdb |
return nil
} |