mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00

This commit adds an option to the checkpoint command to export a checkpoint into a tar.gz file as well as importing a checkpoint tar.gz file during restore. With all checkpoint artifacts in one file it is possible to easily transfer a checkpoint and thus enabling container migration in Podman. With the following steps it is possible to migrate a running container from one system (source) to another (destination). Source system: * podman container checkpoint -l -e /tmp/checkpoint.tar.gz * scp /tmp/checkpoint.tar.gz destination:/tmp Destination system: * podman pull 'container-image-as-on-source-system' * podman container restore -i /tmp/checkpoint.tar.gz The exported tar.gz file contains the checkpoint image as created by CRIU and a few additional JSON files describing the state of the checkpointed container. Now the container is running on the destination system with the same state just as during checkpointing. If the container is kept running on the source system with the checkpoint flag '-R', the result will be that the same container is running on two different hosts. Signed-off-by: Adrian Reber <areber@redhat.com>
72 lines
2.6 KiB
Go
72 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
|
"github.com/containers/libpod/libpod"
|
|
"github.com/containers/libpod/pkg/adapter"
|
|
"github.com/containers/libpod/pkg/rootless"
|
|
"github.com/pkg/errors"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
checkpointCommand cliconfig.CheckpointValues
|
|
checkpointDescription = `
|
|
podman container checkpoint
|
|
|
|
Checkpoints one or more running containers. The container name or ID can be used.
|
|
`
|
|
_checkpointCommand = &cobra.Command{
|
|
Use: "checkpoint [flags] CONTAINER [CONTAINER...]",
|
|
Short: "Checkpoints one or more containers",
|
|
Long: checkpointDescription,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
checkpointCommand.InputArgs = args
|
|
checkpointCommand.GlobalFlags = MainGlobalOpts
|
|
checkpointCommand.Remote = remoteclient
|
|
return checkpointCmd(&checkpointCommand)
|
|
},
|
|
Args: func(cmd *cobra.Command, args []string) error {
|
|
return checkAllAndLatest(cmd, args, false)
|
|
},
|
|
Example: `podman container checkpoint --keep ctrID
|
|
podman container checkpoint --all
|
|
podman container checkpoint --leave-running --latest`,
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
checkpointCommand.Command = _checkpointCommand
|
|
checkpointCommand.SetHelpTemplate(HelpTemplate())
|
|
checkpointCommand.SetUsageTemplate(UsageTemplate())
|
|
|
|
flags := checkpointCommand.Flags()
|
|
flags.BoolVarP(&checkpointCommand.Keep, "keep", "k", false, "Keep all temporary checkpoint files")
|
|
flags.BoolVarP(&checkpointCommand.LeaveRunning, "leave-running", "R", false, "Leave the container running after writing checkpoint to disk")
|
|
flags.BoolVar(&checkpointCommand.TcpEstablished, "tcp-established", false, "Checkpoint a container with established TCP connections")
|
|
flags.BoolVarP(&checkpointCommand.All, "all", "a", false, "Checkpoint all running containers")
|
|
flags.BoolVarP(&checkpointCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
|
|
flags.StringVarP(&checkpointCommand.Export, "export", "e", "", "Export the checkpoint image to a tar.gz")
|
|
markFlagHiddenForRemoteClient("latest", flags)
|
|
}
|
|
|
|
func checkpointCmd(c *cliconfig.CheckpointValues) error {
|
|
if rootless.IsRootless() {
|
|
return errors.New("checkpointing a container requires root")
|
|
}
|
|
|
|
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
|
if err != nil {
|
|
return errors.Wrapf(err, "could not get runtime")
|
|
}
|
|
defer runtime.Shutdown(false)
|
|
|
|
options := libpod.ContainerCheckpointOptions{
|
|
Keep: c.Keep,
|
|
KeepRunning: c.LeaveRunning,
|
|
TCPEstablished: c.TcpEstablished,
|
|
TargetFile: c.Export,
|
|
}
|
|
return runtime.Checkpoint(c, options)
|
|
}
|