Skip to content
Closed
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
18 changes: 18 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,19 +45,28 @@ 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 \
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 \
xmlto \
libzfs-dev \
--no-install-recommends

Expand All @@ -80,6 +91,13 @@ RUN cd /usr/src/lxc \
&& make install \
&& ldconfig

# 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.4.2
RUN curl -sSL https://golang.org/dl/go${GO_VERSION}.src.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"
)

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")
flCheckTcp = cmd.Bool([]string{"-allow-tcp"}, false, "allow checkpointing tcp connections")
flExtUnix = cmd.Bool([]string{"-allow-ext-unix"}, false, "allow checkpointing external unix connections")
flShell = cmd.Bool([]string{"-allow-shell"}, false, "allow checkpointing shell jobs")
)

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: *flCheckTcp,
ExternalUnixConnections: *flExtUnix,
ShellJob: *flShell,
}

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"
)

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")
flCheckTcp = cmd.Bool([]string{"-allow-tcp"}, false, "allow restoring tcp connections")
flExtUnix = cmd.Bool([]string{"-allow-ext-unix"}, false, "allow restoring external unix connections")
flShell = cmd.Bool([]string{"-allow-shell"}, false, "allow restoring shell jobs")
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: *flCheckTcp,
ExternalUnixConnections: *flExtUnix,
ShellJob: *flShell,
},
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
}
3 changes: 3 additions & 0 deletions api/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func httpError(w http.ResponseWriter, err error) {
// json encoding.
func writeJSON(w http.ResponseWriter, code int, v interface{}) error {
w.Header().Set("Content-Type", "application/json")

w.WriteHeader(code)
return json.NewEncoder(w).Encode(v)
}
Expand Down Expand Up @@ -365,6 +366,8 @@ func createRouter(s *Server) *mux.Router {
},
}

addExperimentalRoutes(s, m)

// If "api-cors-header" is not given, but "api-enable-cors" is true, we set cors to "*"
// otherwise, all head values will be passed to HTTP handler
corsHeaders := s.cfg.CorsHeaders
Expand Down
55 changes: 55 additions & 0 deletions api/server/server_experimental_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

package server

import (
"encoding/json"
"fmt"
"github.com/docker/docker/pkg/version"
"github.com/docker/docker/runconfig"
"net/http"
)

func addExperimentalRoutes(s *Server, m map[string]map[string]HTTPAPIFunc) {
m["POST"]["/containers/{name:.*}/checkpoint"] = s.postContainersCheckpoint
m["POST"]["/containers/{name:.*}/restore"] = s.postContainersRestore
}

func (s *Server) registerSubRouter() {
httpHandler := s.daemon.NetworkApiRouter()

Expand All @@ -15,3 +28,45 @@ func (s *Server) registerSubRouter() {
subrouter = s.router.PathPrefix("/services").Subrouter()
subrouter.Methods("GET", "POST", "PUT", "DELETE").HandlerFunc(httpHandler)
}

func (s *Server) postContainersCheckpoint(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if vars == nil {
return fmt.Errorf("Missing parameter")
}
if err := parseForm(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 *Server) postContainersRestore(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if vars == nil {
return fmt.Errorf("Missing parameter")
}
if err := parseForm(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
}
4 changes: 4 additions & 0 deletions api/server/server_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@

package server

func addExperimentalRoutes(s *Server, m map[string]map[string]HTTPAPIFunc) {

}

func (s *Server) registerSubRouter() {
}
22 changes: 12 additions & 10 deletions api/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,18 @@ type ExecStartCheck struct {
// ContainerState stores container's running state
// it's part of ContainerJSONBase and will return by "inspect" command
type ContainerState struct {
Running bool
Paused bool
Restarting bool
OOMKilled bool
Dead bool
Pid int
ExitCode int
Error string
StartedAt string
FinishedAt 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
56 changes: 56 additions & 0 deletions daemon/checkpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package daemon

import (
"fmt"

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

// Checkpoint a running container.
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 err := container.Checkpoint(opts); err != nil {
return fmt.Errorf("Cannot checkpoint container %s: %s", name, err)
}

container.LogEvent("checkpoint")
return nil
}

// Restore a checkpointed container.
func (daemon *Daemon) ContainerRestore(name string, opts *runconfig.CriuConfig, forceRestore bool) error {
container, err := daemon.Get(name)
if err != nil {
return err
}

if !forceRestore {
// TODO: It's possible we only want to bypass the checkpointed check,
// I'm not sure how this will work if the container is already running
if container.IsRunning() {
return fmt.Errorf("Container %s already running", name)
}

if !container.IsCheckpointed() {
return fmt.Errorf("Container %s is not checkpointed", name)
}
} else {
if !container.HasBeenCheckpointed() && opts.ImagesDirectory == "" {
return fmt.Errorf("You must specify an image directory to restore from %s", name)
}
}

if err = container.Restore(opts, forceRestore); err != nil {
container.LogEvent("die")
return fmt.Errorf("Cannot restore container %s: %s", name, err)
}

container.LogEvent("restore")
return nil
}
8 changes: 6 additions & 2 deletions daemon/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (container *Container) Start() (err error) {
// backwards API compatibility.
container.hostConfig = runconfig.SetDefaultNetModeIfBlank(container.hostConfig)

if err := container.initializeNetworking(); err != nil {
if err := container.initializeNetworking(false); err != nil {
return err
}
linkedEnv, err := container.setupLinkedContainers()
Expand Down Expand Up @@ -343,7 +343,11 @@ func (container *Container) isNetworkAllocated() bool {
// 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()
if container.IsCheckpointed() {
logrus.Debugf("not calling ReleaseNetwork() for checkpointed container %s", container.ID)
} else {
container.ReleaseNetwork(false)
}

if err := container.CleanupStorage(); err != nil {
logrus.Errorf("%v: Failed to cleanup storage: %v", container.ID, err)
Expand Down
Loading