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

External containers are containers created outside of Podman. For example Buildah and CRI-O Containers. $ buildah from alpine alpine-working-container $ buildah run alpine-working-container touch /test $ podman container exists --external alpine-working-container $ podman container diff alpine-working-container C /etc A /test Added --external flag to refer to external containers, rather then --storage. Added --external for podman container exists and modified podman ps to use --external rather then --storage. It was felt that --storage would confuse the user into thinking about changing the storage driver or options. --storage is still supported through the use of aliases. Finally podman contianer diff, does not require the --external flag, since it there is little change of users making the mistake, and would just be a pain for the user to remember the flag. podman container exists --external is required because it could fool scripts that rely on the existance of a Podman container, and there is a potential for a partial deletion of a container, which could mess up existing users. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package containers
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/containers/podman/v2/cmd/podman/registry"
|
|
"github.com/containers/podman/v2/pkg/domain/entities"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
containerExistsDescription = `If the named container exists in local storage, podman container exists exits with 0, otherwise the exit code will be 1.`
|
|
|
|
existsCommand = &cobra.Command{
|
|
Use: "exists [flags] CONTAINER",
|
|
Short: "Check if a container exists in local storage",
|
|
Long: containerExistsDescription,
|
|
Example: `podman container exists --external containerID
|
|
podman container exists myctr || podman run --name myctr [etc...]`,
|
|
RunE: exists,
|
|
Args: cobra.ExactArgs(1),
|
|
DisableFlagsInUseLine: true,
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
|
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
|
|
Command: existsCommand,
|
|
Parent: containerCmd,
|
|
})
|
|
flags := existsCommand.Flags()
|
|
flags.Bool("external", false, "Check external storage containers as well as Podman containers")
|
|
}
|
|
|
|
func exists(cmd *cobra.Command, args []string) error {
|
|
external, err := cmd.Flags().GetBool("external")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
options := entities.ContainerExistsOptions{
|
|
External: external,
|
|
}
|
|
response, err := registry.ContainerEngine().ContainerExists(context.Background(), args[0], options)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !response.Value {
|
|
registry.SetExitCode(1)
|
|
}
|
|
return nil
|
|
}
|