-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update checkpoint and restore to latest docker/master.
- C/R is now an EXPERIMENTAL level feature. - Requires CRIU 1.6 (and builds it from source in the Dockerfile) - Introduces checkpoint and restore as top level cli methods (will likely change) Signed-off-by: Ross Boucher <[email protected]>
- Loading branch information
Showing
29 changed files
with
786 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// +build !experimental | ||
|
||
package local | ||
|
||
func addExperimentalRoutes(r *router) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.