Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ RUN echo deb http://ppa.launchpad.net/zfs-native/stable/ubuntu trusty main > /et
# Packaged dependencies
RUN apt-get update && apt-get install -y \
apparmor \
asciidoc \
aufs-tools \
automake \
bash-completion \
bsdmainutils \
btrfs-tools \
build-essential \
createrepo \
Expand All @@ -43,22 +45,30 @@ RUN apt-get update && apt-get install -y \
gcc-mingw-w64 \
git \
iptables \
libaio-dev \
libapparmor-dev \
libcap-dev \
libprotobuf-c0-dev \
libprotobuf-dev \
libsqlite3-dev \
libsystemd-journal-dev \
mercurial \
parallel \
pkg-config \
protobuf-compiler \
protobuf-c-compiler \
python-minimal \
python-mock \
python-pip \
python-protobuf \
python-websocket \
reprepro \
ruby1.9.1 \
ruby1.9.1-dev \
s3cmd=1.1.0* \
ubuntu-zfs \
xfsprogs \
xmlto \
libzfs-dev \
--no-install-recommends

Expand All @@ -73,6 +83,13 @@ RUN cd /usr/local/lvm2 \
&& make install_device-mapper
# see https://git.fedorahosted.org/cgit/lvm2.git/tree/INSTALL

# Install Criu
RUN mkdir -p /usr/src/criu \
&& curl -sSL https://github.com/xemul/criu/archive/v1.6.tar.gz | tar -v -C /usr/src/criu/ -xz --strip-components=1
RUN cd /usr/src/criu \
&& make \
&& make install

# Install Go
ENV GO_VERSION 1.5.1
RUN curl -sSL "https://storage.googleapis.com/golang/go${GO_VERSION}.linux-amd64.tar.gz" | tar -v -C /usr/local -xz
Expand Down
55 changes: 55 additions & 0 deletions api/client/checkpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// +build experimental

package client

import (
"fmt"

Cli "github.com/docker/docker/cli"
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/runconfig"
)

// CmdCheckpoint checkpoints the process running in a container
//
// Usage: docker checkpoint CONTAINER
func (cli *DockerCli) CmdCheckpoint(args ...string) error {
cmd := Cli.Subcmd("checkpoint", []string{"CONTAINER [CONTAINER...]"}, "Checkpoint one or more running containers", true)
cmd.Require(flag.Min, 1)

var (
flImgDir = cmd.String([]string{"-image-dir"}, "", "directory for storing checkpoint image files")
flWorkDir = cmd.String([]string{"-work-dir"}, "", "directory for storing log file")
flLeaveRunning = cmd.Bool([]string{"-leave-running"}, false, "leave the container running after checkpoint")
)

if err := cmd.ParseFlags(args, true); err != nil {
return err
}

if cmd.NArg() < 1 {
cmd.Usage()
return nil
}

criuOpts := &runconfig.CriuConfig{
ImagesDirectory: *flImgDir,
WorkDirectory: *flWorkDir,
LeaveRunning: *flLeaveRunning,
TCPEstablished: true,
ExternalUnixConnections: true,
FileLocks: true,
}

var encounteredError error
for _, name := range cmd.Args() {
_, _, err := readBody(cli.call("POST", "/containers/"+name+"/checkpoint", criuOpts, nil))
if err != nil {
fmt.Fprintf(cli.err, "%s\n", err)
encounteredError = fmt.Errorf("Error: failed to checkpoint one or more containers")
} else {
fmt.Fprintf(cli.out, "%s\n", name)
}
}
return encounteredError
}
57 changes: 57 additions & 0 deletions api/client/restore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// +build experimental

package client

import (
"fmt"

Cli "github.com/docker/docker/cli"
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/runconfig"
)

// CmdRestore restores the process in a checkpointed container
//
// Usage: docker restore CONTAINER
func (cli *DockerCli) CmdRestore(args ...string) error {
cmd := Cli.Subcmd("restore", []string{"CONTAINER [CONTAINER...]"}, "Restore one or more checkpointed containers", true)
cmd.Require(flag.Min, 1)

var (
flImgDir = cmd.String([]string{"-image-dir"}, "", "directory to restore image files from")
flWorkDir = cmd.String([]string{"-work-dir"}, "", "directory for restore log")
flForce = cmd.Bool([]string{"-force"}, false, "bypass checks for current container state")
)

if err := cmd.ParseFlags(args, true); err != nil {
return err
}

if cmd.NArg() < 1 {
cmd.Usage()
return nil
}

restoreOpts := &runconfig.RestoreConfig{
CriuOpts: runconfig.CriuConfig{
ImagesDirectory: *flImgDir,
WorkDirectory: *flWorkDir,
TCPEstablished: true,
ExternalUnixConnections: true,
FileLocks: true,
},
ForceRestore: *flForce,
}

var encounteredError error
for _, name := range cmd.Args() {
_, _, err := readBody(cli.call("POST", "/containers/"+name+"/restore", restoreOpts, nil))
if err != nil {
fmt.Fprintf(cli.err, "%s\n", err)
encounteredError = fmt.Errorf("Error: failed to restore one or more containers")
} else {
fmt.Fprintf(cli.out, "%s\n", name)
}
}
return encounteredError
}
2 changes: 2 additions & 0 deletions api/server/router/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ func (r *router) initRoutes() {
NewDeleteRoute("/containers/{name:.*}", r.deleteContainers),
NewDeleteRoute("/images/{name:.*}", r.deleteImages),
}

addExperimentalRoutes(r)
}

func optionsHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
Expand Down
65 changes: 65 additions & 0 deletions api/server/router/local/local_experimental.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// +build experimental

package local

import (
"encoding/json"
"fmt"
"net/http"

"github.com/docker/docker/api/server/httputils"
dkrouter "github.com/docker/docker/api/server/router"
"github.com/docker/docker/runconfig"
"golang.org/x/net/context"
)

func addExperimentalRoutes(r *router) {
newRoutes := []dkrouter.Route{
NewPostRoute("/containers/{name:.*}/checkpoint", r.postContainersCheckpoint),
NewPostRoute("/containers/{name:.*}/restore", r.postContainersRestore),
}

r.routes = append(r.routes, newRoutes...)
}

func (s *router) postContainersCheckpoint(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if vars == nil {
return fmt.Errorf("Missing parameter")
}
if err := httputils.CheckForJSON(r); err != nil {
return err
}

criuOpts := &runconfig.CriuConfig{}
if err := json.NewDecoder(r.Body).Decode(criuOpts); err != nil {
return err
}

if err := s.daemon.ContainerCheckpoint(vars["name"], criuOpts); err != nil {
return err
}

w.WriteHeader(http.StatusNoContent)
return nil
}

func (s *router) postContainersRestore(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if vars == nil {
return fmt.Errorf("Missing parameter")
}
if err := httputils.CheckForJSON(r); err != nil {
return err
}

restoreOpts := runconfig.RestoreConfig{}
if err := json.NewDecoder(r.Body).Decode(&restoreOpts); err != nil {
return err
}

if err := s.daemon.ContainerRestore(vars["name"], &restoreOpts.CriuOpts, restoreOpts.ForceRestore); err != nil {
return err
}

w.WriteHeader(http.StatusNoContent)
return nil
}
6 changes: 6 additions & 0 deletions api/server/router/local/local_stable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// +build !experimental

package local

func addExperimentalRoutes(r *router) {
}
24 changes: 13 additions & 11 deletions api/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,19 @@ type ExecStartCheck struct {
// ContainerState stores container's running state
// it's part of ContainerJSONBase and will return by "inspect" command
type ContainerState struct {
Status string
Running bool
Paused bool
Restarting bool
OOMKilled bool
Dead bool
Pid int
ExitCode int
Error string
StartedAt string
FinishedAt string
Status string
Running bool
Paused bool
Checkpointed bool
Restarting bool
OOMKilled bool
Dead bool
Pid int
ExitCode int
Error string
StartedAt string
FinishedAt string
CheckpointedAt string `json:"-"`
}

// ContainerJSONBase contains response of Remote API:
Expand Down
65 changes: 65 additions & 0 deletions daemon/checkpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package daemon

import (
"fmt"
"os"
"path/filepath"

"github.com/docker/docker/runconfig"
)

// ContainerCheckpoint checkpoints the process running in a container with CRIU
func (daemon *Daemon) ContainerCheckpoint(name string, opts *runconfig.CriuConfig) error {
container, err := daemon.Get(name)
if err != nil {
return err
}
if !container.IsRunning() {
return fmt.Errorf("Container %s not running", name)
}

if opts.ImagesDirectory == "" {
opts.ImagesDirectory = filepath.Join(container.root, "criu.image")
if err := os.MkdirAll(opts.ImagesDirectory, 0755); err != nil && !os.IsExist(err) {
return err
}
}

if opts.WorkDirectory == "" {
opts.WorkDirectory = filepath.Join(container.root, "criu.work")
if err := os.MkdirAll(opts.WorkDirectory, 0755); err != nil && !os.IsExist(err) {
return err
}
}

if err := daemon.Checkpoint(container, opts); err != nil {
return fmt.Errorf("Cannot checkpoint container %s: %s", name, err)
}

container.SetCheckpointed(opts.LeaveRunning)

if opts.LeaveRunning == false {
daemon.Cleanup(container)
}

// commit the filesystem as well, support AUFS only
commitCfg := &ContainerCommitConfig{
Pause: true,
Config: container.Config,
}
img, err := daemon.Commit(name, commitCfg)
if err != nil {
return err
}
// Update the criu image path and image ID of the container
criuImagePath := opts.ImagesDirectory
container.CriuimagePaths[criuImagePath] = img.ID
// Update image layer of the committed container
container.ImageID = img.ID

if err := container.toDisk(); err != nil {
return fmt.Errorf("Cannot update config for container: %s", err)
}

return nil
}
1 change: 0 additions & 1 deletion daemon/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ func attach(streamConfig *streamConfig, openStdin, stdinOnce, tty bool, stdin io
_, err = copyEscapable(cStdin, stdin)
} else {
_, err = io.Copy(cStdin, stdin)

}
if err == io.ErrClosedPipe {
err = nil
Expand Down
Loading