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

podman container clone takes the id of an existing continer and creates a specgen from the given container's config recreating all proper namespaces and overriding spec options like resource limits and the container name if given in the cli options this command utilizes the common function DefineCreateFlags meaning that we can funnel as many create options as we want into clone over time allowing the user to clone with as much or as little of the original config as they want. container clone takes a second argument which is a new name and a third argument which is an image name to use instead of the original container's the current supported flags are: --destroy (remove the original container) --name (new ctr name) --cpus (sets cpu period and quota) --cpuset-cpus --cpu-period --cpu-rt-period --cpu-rt-runtime --cpu-shares --cpuset-mems --memory --run resolves #10875 Signed-off-by: cdoern <cdoern@redhat.com> Signed-off-by: cdoern <cbdoer23@g.holycross.edu> Signed-off-by: cdoern <cdoern@redhat.com>
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package specgenutil
|
|
|
|
import (
|
|
"github.com/containers/common/pkg/config"
|
|
"github.com/containers/podman/v4/pkg/domain/entities"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// validate determines if the flags and values given by the user are valid. things checked
|
|
// by validate must not need any state information on the flag (i.e. changed)
|
|
func validate(c *entities.ContainerCreateOptions) error {
|
|
var ()
|
|
if c.Rm && (c.Restart != "" && c.Restart != "no" && c.Restart != "on-failure") {
|
|
return errors.Errorf(`the --rm option conflicts with --restart, when the restartPolicy is not "" and "no"`)
|
|
}
|
|
|
|
if _, err := config.ParsePullPolicy(c.Pull); err != nil {
|
|
return err
|
|
}
|
|
|
|
var imageVolType = map[string]string{
|
|
"bind": "",
|
|
"tmpfs": "",
|
|
"ignore": "",
|
|
}
|
|
if _, ok := imageVolType[c.ImageVolume]; !ok {
|
|
if c.IsInfra {
|
|
c.ImageVolume = "bind"
|
|
} else if c.IsClone { // the image volume type will be deduced later from the container we are cloning
|
|
return nil
|
|
} else {
|
|
return errors.Errorf("invalid image-volume type %q. Pick one of bind, tmpfs, or ignore", c.ImageVolume)
|
|
}
|
|
}
|
|
return nil
|
|
}
|