summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/common/completion.go7
-rw-r--r--cmd/podman/containers/cleanup.go8
-rw-r--r--cmd/podman/containers/ps.go4
-rw-r--r--cmd/podman/generate/generate.go2
-rw-r--r--cmd/podman/images/build.go14
-rw-r--r--cmd/podman/images/prune.go5
-rw-r--r--cmd/podman/images/utils_linux.go4
-rw-r--r--cmd/podman/inspect/inspect.go2
-rw-r--r--cmd/podman/machine/init.go8
-rw-r--r--cmd/podman/machine/list.go81
-rw-r--r--cmd/podman/play/play.go2
-rw-r--r--cmd/podman/registry/config.go7
-rw-r--r--cmd/podman/root.go11
-rw-r--r--cmd/podman/system/prune.go6
-rw-r--r--cmd/podman/system/service.go4
15 files changed, 114 insertions, 51 deletions
diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go
index 2ea5fa10f..90522438d 100644
--- a/cmd/podman/common/completion.go
+++ b/cmd/podman/common/completion.go
@@ -194,21 +194,14 @@ func getImages(cmd *cobra.Command, toComplete string) ([]string, cobra.ShellComp
} else {
// suggested "registry.fedoraproject.org/f29/httpd:latest" as
// - "registry.fedoraproject.org/f29/httpd:latest"
- // - "registry.fedoraproject.org/f29/httpd"
// - "f29/httpd:latest"
- // - "f29/httpd"
// - "httpd:latest"
- // - "httpd"
paths := strings.Split(repo, "/")
for i := range paths {
suggestionWithTag := strings.Join(paths[i:], "/")
if strings.HasPrefix(suggestionWithTag, toComplete) {
suggestions = append(suggestions, suggestionWithTag)
}
- suggestionWithoutTag := strings.SplitN(strings.SplitN(suggestionWithTag, ":", 2)[0], "@", 2)[0]
- if strings.HasPrefix(suggestionWithoutTag, toComplete) {
- suggestions = append(suggestions, suggestionWithoutTag)
- }
}
}
}
diff --git a/cmd/podman/containers/cleanup.go b/cmd/podman/containers/cleanup.go
index 98706c575..a3d339358 100644
--- a/cmd/podman/containers/cleanup.go
+++ b/cmd/podman/containers/cleanup.go
@@ -80,7 +80,7 @@ func cleanup(cmd *cobra.Command, args []string) error {
// is via syslog.
// As such, we need to logrus.Errorf our errors to ensure they
// are properly printed if --syslog is set.
- logrus.Errorf("Error running container cleanup: %v", err)
+ logrus.Errorf("Running container cleanup: %v", err)
return err
}
for _, r := range responses {
@@ -89,15 +89,15 @@ func cleanup(cmd *cobra.Command, args []string) error {
continue
}
if r.RmErr != nil {
- logrus.Errorf("Error removing container: %v", r.RmErr)
+ logrus.Errorf("Removing container: %v", r.RmErr)
errs = append(errs, r.RmErr)
}
if r.RmiErr != nil {
- logrus.Errorf("Error removing image: %v", r.RmiErr)
+ logrus.Errorf("Removing image: %v", r.RmiErr)
errs = append(errs, r.RmiErr)
}
if r.CleanErr != nil {
- logrus.Errorf("Error cleaning up container: %v", r.CleanErr)
+ logrus.Errorf("Cleaning up container: %v", r.CleanErr)
errs = append(errs, r.CleanErr)
}
}
diff --git a/cmd/podman/containers/ps.go b/cmd/podman/containers/ps.go
index afb8edd91..9687cd5bd 100644
--- a/cmd/podman/containers/ps.go
+++ b/cmd/podman/containers/ps.go
@@ -375,6 +375,10 @@ func (l psReporter) State() string {
// Status is a synonym for State()
func (l psReporter) Status() string {
+ hc := l.ListContainer.Status
+ if hc != "" {
+ return l.State() + " (" + hc + ")"
+ }
return l.State()
}
diff --git a/cmd/podman/generate/generate.go b/cmd/podman/generate/generate.go
index 6b48a342e..a42aa9f21 100644
--- a/cmd/podman/generate/generate.go
+++ b/cmd/podman/generate/generate.go
@@ -11,7 +11,7 @@ var (
// Command: podman _generate_
generateCmd = &cobra.Command{
Use: "generate",
- Short: "Generate structured data based on containers, pods or volumes.",
+ Short: "Generate structured data based on containers, pods or volumes",
Long: "Generate structured data (e.g., Kubernetes YAML or systemd units) based on containers, pods or volumes.",
RunE: validate.SubCommandExists,
}
diff --git a/cmd/podman/images/build.go b/cmd/podman/images/build.go
index 642da0c83..4c563ed27 100644
--- a/cmd/podman/images/build.go
+++ b/cmd/podman/images/build.go
@@ -131,7 +131,7 @@ func buildFlags(cmd *cobra.Command) {
// --pull flag
flag := budFlags.Lookup("pull")
if err := flag.Value.Set("true"); err != nil {
- logrus.Errorf("unable to set --pull to true: %v", err)
+ logrus.Errorf("Unable to set --pull to true: %v", err)
}
flag.DefValue = "true"
flag.Usage = "Always attempt to pull the image (errors are fatal)"
@@ -148,13 +148,13 @@ func buildFlags(cmd *cobra.Command) {
useLayersVal := useLayers()
buildOpts.Layers = useLayersVal == "true"
if err := flag.Value.Set(useLayersVal); err != nil {
- logrus.Errorf("unable to set --layers to %v: %v", useLayersVal, err)
+ logrus.Errorf("Unable to set --layers to %v: %v", useLayersVal, err)
}
flag.DefValue = useLayersVal
// --force-rm flag
flag = layerFlags.Lookup("force-rm")
if err := flag.Value.Set("true"); err != nil {
- logrus.Errorf("unable to set --force-rm to true: %v", err)
+ logrus.Errorf("Unable to set --force-rm to true: %v", err)
}
flag.DefValue = "true"
flags.AddFlagSet(&layerFlags)
@@ -162,7 +162,7 @@ func buildFlags(cmd *cobra.Command) {
// FromAndBud flags
fromAndBudFlags, err := buildahCLI.GetFromAndBudFlags(&buildOpts.FromAndBudResults, &buildOpts.UserNSResults, &buildOpts.NameSpaceResults)
if err != nil {
- logrus.Errorf("error setting up build flags: %v", err)
+ logrus.Errorf("Setting up build flags: %v", err)
os.Exit(1)
}
// --http-proxy flag
@@ -171,7 +171,7 @@ func buildFlags(cmd *cobra.Command) {
flag = fromAndBudFlags.Lookup("http-proxy")
buildOpts.HTTPProxy = false
if err := flag.Value.Set("false"); err != nil {
- logrus.Errorf("unable to set --https-proxy to %v: %v", false, err)
+ logrus.Errorf("Unable to set --https-proxy to %v: %v", false, err)
}
flag.DefValue = "false"
}
@@ -184,7 +184,7 @@ func buildFlags(cmd *cobra.Command) {
flag = flags.Lookup("isolation")
buildOpts.Isolation = buildahDefine.OCI
if err := flag.Value.Set(buildahDefine.OCI); err != nil {
- logrus.Errorf("unable to set --isolation to %v: %v", buildahDefine.OCI, err)
+ logrus.Errorf("Unable to set --isolation to %v: %v", buildahDefine.OCI, err)
}
flag.DefValue = buildahDefine.OCI
_ = flags.MarkHidden("disable-content-trust")
@@ -228,7 +228,7 @@ func build(cmd *cobra.Command, args []string) error {
// Delete it later.
defer func() {
if err = os.RemoveAll(tempDir); err != nil {
- logrus.Errorf("error removing temporary directory %q: %v", contextDir, err)
+ logrus.Errorf("Removing temporary directory %q: %v", contextDir, err)
}
}()
contextDir = filepath.Join(tempDir, subDir)
diff --git a/cmd/podman/images/prune.go b/cmd/podman/images/prune.go
index 8a484495a..6c39e5c69 100644
--- a/cmd/podman/images/prune.go
+++ b/cmd/podman/images/prune.go
@@ -41,6 +41,7 @@ func init() {
flags := pruneCmd.Flags()
flags.BoolVarP(&pruneOpts.All, "all", "a", false, "Remove all images not in use by containers, not just dangling ones")
+ flags.BoolVarP(&pruneOpts.External, "external", "", false, "Remove images even when they are used by external containers (e.g., by build containers)")
flags.BoolVarP(&force, "force", "f", false, "Do not prompt for confirmation")
filterFlagName := "filter"
@@ -80,7 +81,7 @@ func prune(cmd *cobra.Command, args []string) error {
func createPruneWarningMessage(pruneOpts entities.ImagePruneOptions) string {
question := "Are you sure you want to continue? [y/N] "
if pruneOpts.All {
- return "WARNING! This will remove all images without at least one container associated to them.\n" + question
+ return "WARNING! This command removes all images without at least one container associated with them.\n" + question
}
- return "WARNING! This will remove all dangling images.\n" + question
+ return "WARNING! This command removes all dangling images.\n" + question
}
diff --git a/cmd/podman/images/utils_linux.go b/cmd/podman/images/utils_linux.go
index 5521abab4..f7c159415 100644
--- a/cmd/podman/images/utils_linux.go
+++ b/cmd/podman/images/utils_linux.go
@@ -24,7 +24,7 @@ func setupPipe() (string, func() <-chan error, error) {
err = unix.Mkfifo(pipePath, 0600)
if err != nil {
if e := os.RemoveAll(pipeDir); e != nil {
- logrus.Errorf("error removing named pipe: %q", e)
+ logrus.Errorf("Removing named pipe: %q", e)
}
return "", nil, errors.Wrapf(err, "error creating named pipe")
}
@@ -40,7 +40,7 @@ func setupPipe() (string, func() <-chan error, error) {
}()
return pipePath, func() <-chan error {
if e := os.RemoveAll(pipeDir); e != nil {
- logrus.Errorf("error removing named pipe: %q", e)
+ logrus.Errorf("Removing named pipe: %q", e)
}
return errc
}, nil
diff --git a/cmd/podman/inspect/inspect.go b/cmd/podman/inspect/inspect.go
index 4c7fa33a4..64b586388 100644
--- a/cmd/podman/inspect/inspect.go
+++ b/cmd/podman/inspect/inspect.go
@@ -220,7 +220,7 @@ func (i *inspector) inspect(namesOrIDs []string) error {
err = printTmpl(tmpType, row, data)
}
if err != nil {
- logrus.Errorf("Error printing inspect output: %v", err)
+ logrus.Errorf("Printing inspect output: %v", err)
}
if len(errs) > 0 {
diff --git a/cmd/podman/machine/init.go b/cmd/podman/machine/init.go
index 19f31d1a6..adde887f7 100644
--- a/cmd/podman/machine/init.go
+++ b/cmd/podman/machine/init.go
@@ -42,7 +42,7 @@ func init() {
cpusFlagName := "cpus"
flags.Uint64Var(
&initOpts.CPUS,
- cpusFlagName, 1,
+ cpusFlagName, cfg.Machine.CPUs,
"Number of CPUs",
)
_ = initCmd.RegisterFlagCompletionFunc(cpusFlagName, completion.AutocompleteNone)
@@ -50,7 +50,7 @@ func init() {
diskSizeFlagName := "disk-size"
flags.Uint64Var(
&initOpts.DiskSize,
- diskSizeFlagName, 10,
+ diskSizeFlagName, cfg.Machine.DiskSize,
"Disk size in GB",
)
@@ -59,7 +59,7 @@ func init() {
memoryFlagName := "memory"
flags.Uint64VarP(
&initOpts.Memory,
- memoryFlagName, "m", 2048,
+ memoryFlagName, "m", cfg.Machine.Memory,
"Memory in MB",
)
_ = initCmd.RegisterFlagCompletionFunc(memoryFlagName, completion.AutocompleteNone)
@@ -71,7 +71,7 @@ func init() {
)
ImagePathFlagName := "image-path"
- flags.StringVar(&initOpts.ImagePath, ImagePathFlagName, cfg.Engine.MachineImage, "Path to qcow image")
+ flags.StringVar(&initOpts.ImagePath, ImagePathFlagName, cfg.Machine.Image, "Path to qcow image")
_ = initCmd.RegisterFlagCompletionFunc(ImagePathFlagName, completion.AutocompleteDefault)
IgnitionPathFlagName := "ignition-path"
diff --git a/cmd/podman/machine/list.go b/cmd/podman/machine/list.go
index d4360bb9b..95b7d860f 100644
--- a/cmd/podman/machine/list.go
+++ b/cmd/podman/machine/list.go
@@ -3,13 +3,16 @@
package machine
import (
+ "encoding/json"
"os"
"sort"
+ "strconv"
"time"
"github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/config"
"github.com/containers/common/pkg/report"
+ "github.com/containers/podman/v3/cmd/podman/common"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/validate"
"github.com/containers/podman/v3/pkg/machine"
@@ -40,10 +43,15 @@ type listFlagType struct {
}
type machineReporter struct {
- Name string
- Created string
- LastUp string
- VMType string
+ Name string
+ Default bool
+ Created string
+ Running bool
+ LastUp string
+ VMType string
+ CPUs uint64
+ Memory string
+ DiskSize string
}
func init() {
@@ -54,8 +62,8 @@ func init() {
flags := lsCmd.Flags()
formatFlagName := "format"
- flags.StringVar(&listFlag.format, formatFlagName, "{{.Name}}\t{{.VMType}}\t{{.Created}}\t{{.LastUp}}\n", "Format volume output using Go template")
- _ = lsCmd.RegisterFlagCompletionFunc(formatFlagName, completion.AutocompleteNone)
+ flags.StringVar(&listFlag.format, formatFlagName, "{{.Name}}\t{{.VMType}}\t{{.Created}}\t{{.LastUp}}\t{{.CPUs}}\t{{.Memory}}\t{{.DiskSize}}\n", "Format volume output using JSON or a Go template")
+ _ = lsCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(machineReporter{}))
flags.BoolVar(&listFlag.noHeading, "noheading", false, "Do not print headers")
}
@@ -75,6 +83,21 @@ func list(cmd *cobra.Command, args []string) error {
sort.Slice(listResponse, func(i, j int) bool {
return listResponse[i].Running
})
+
+ if report.IsJSON(listFlag.format) {
+ machineReporter, err := toMachineFormat(listResponse)
+ if err != nil {
+ return err
+ }
+
+ b, err := json.Marshal(machineReporter)
+ if err != nil {
+ return err
+ }
+ os.Stdout.Write(b)
+ return nil
+ }
+
machineReporter, err := toHumanFormat(listResponse)
if err != nil {
return err
@@ -85,8 +108,11 @@ func list(cmd *cobra.Command, args []string) error {
func outputTemplate(cmd *cobra.Command, responses []*machineReporter) error {
headers := report.Headers(machineReporter{}, map[string]string{
- "LastUp": "LAST UP",
- "VmType": "VM TYPE",
+ "LastUp": "LAST UP",
+ "VmType": "VM TYPE",
+ "CPUs": "CPUS",
+ "Memory": "MEMORY",
+ "DiskSize": "DISK SIZE",
})
row := report.NormalizeFormat(listFlag.format)
@@ -115,6 +141,42 @@ func outputTemplate(cmd *cobra.Command, responses []*machineReporter) error {
return tmpl.Execute(w, responses)
}
+func strTime(t time.Time) string {
+ iso, err := t.MarshalText()
+ if err != nil {
+ return ""
+ }
+ return string(iso)
+}
+
+func strUint(u uint64) string {
+ return strconv.FormatUint(u, 10)
+}
+
+func toMachineFormat(vms []*machine.ListResponse) ([]*machineReporter, error) {
+ cfg, err := config.ReadCustomConfig()
+ if err != nil {
+ return nil, err
+ }
+
+ machineResponses := make([]*machineReporter, 0, len(vms))
+ for _, vm := range vms {
+ response := new(machineReporter)
+ response.Default = vm.Name == cfg.Engine.ActiveService
+ response.Name = vm.Name
+ response.Running = vm.Running
+ response.LastUp = strTime(vm.LastUp)
+ response.Created = strTime(vm.CreatedAt)
+ response.VMType = vm.VMType
+ response.CPUs = vm.CPUs
+ response.Memory = strUint(vm.Memory * units.MiB)
+ response.DiskSize = strUint(vm.DiskSize * units.GiB)
+
+ machineResponses = append(machineResponses, response)
+ }
+ return machineResponses, nil
+}
+
func toHumanFormat(vms []*machine.ListResponse) ([]*machineReporter, error) {
cfg, err := config.ReadCustomConfig()
if err != nil {
@@ -136,6 +198,9 @@ func toHumanFormat(vms []*machine.ListResponse) ([]*machineReporter, error) {
}
response.Created = units.HumanDuration(time.Since(vm.CreatedAt)) + " ago"
response.VMType = vm.VMType
+ response.CPUs = vm.CPUs
+ response.Memory = units.HumanSize(float64(vm.Memory) * units.MiB)
+ response.DiskSize = units.HumanSize(float64(vm.DiskSize) * units.GiB)
humanResponses = append(humanResponses, response)
}
diff --git a/cmd/podman/play/play.go b/cmd/podman/play/play.go
index f121d6a2d..d676bd701 100644
--- a/cmd/podman/play/play.go
+++ b/cmd/podman/play/play.go
@@ -10,7 +10,7 @@ var (
// Command: podman _play_
playCmd = &cobra.Command{
Use: "play",
- Short: "Play containers, pods or volumes from a structured file.",
+ Short: "Play containers, pods or volumes from a structured file",
Long: "Play structured data (e.g., Kubernetes YAML) based on containers, pods or volumes.",
RunE: validate.SubCommandExists,
}
diff --git a/cmd/podman/registry/config.go b/cmd/podman/registry/config.go
index 50e488b02..b512ba341 100644
--- a/cmd/podman/registry/config.go
+++ b/cmd/podman/registry/config.go
@@ -89,12 +89,7 @@ func newPodmanConfig() {
// use for the containers.conf configuration file.
func setXdgDirs() error {
if !rootless.IsRootless() {
- // unset XDG_RUNTIME_DIR for root
- // Sometimes XDG_RUNTIME_DIR is set to /run/user/0 sometimes it is unset,
- // the inconsistency is causing issues for the dnsname plugin.
- // It is already set to an empty string for conmon so lets do the same
- // for podman. see #10806 and #10745
- return os.Unsetenv("XDG_RUNTIME_DIR")
+ return nil
}
// Setup XDG_RUNTIME_DIR
diff --git a/cmd/podman/root.go b/cmd/podman/root.go
index 02e6dcd27..eb30f1ef6 100644
--- a/cmd/podman/root.go
+++ b/cmd/podman/root.go
@@ -92,6 +92,11 @@ func Execute() {
if registry.GetExitCode() == 0 {
registry.SetExitCode(define.ExecErrorCodeGeneric)
}
+ if registry.IsRemote() {
+ if strings.Contains(err.Error(), "unable to connect to Podman") {
+ fmt.Fprintln(os.Stderr, "Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM")
+ }
+ }
fmt.Fprintln(os.Stderr, formatError(err))
}
os.Exit(registry.GetExitCode())
@@ -175,7 +180,7 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
// Hard code TMPDIR functions to use /var/tmp, if user did not override
if _, ok := os.LookupEnv("TMPDIR"); !ok {
if tmpdir, err := cfg.ImageCopyTmpDir(); err != nil {
- logrus.Warnf("failed to retrieve default tmp dir: %s", err.Error())
+ logrus.Warnf("Failed to retrieve default tmp dir: %s", err.Error())
} else {
os.Setenv("TMPDIR", tmpdir)
}
@@ -313,7 +318,7 @@ func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
pFlags := cmd.PersistentFlags()
if registry.IsRemote() {
if err := lFlags.MarkHidden("remote"); err != nil {
- logrus.Warnf("unable to mark --remote flag as hidden: %s", err.Error())
+ logrus.Warnf("Unable to mark --remote flag as hidden: %s", err.Error())
}
opts.Remote = true
} else {
@@ -387,7 +392,7 @@ func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
"trace",
} {
if err := pFlags.MarkHidden(f); err != nil {
- logrus.Warnf("unable to mark %s flag as hidden: %s", f, err.Error())
+ logrus.Warnf("Unable to mark %s flag as hidden: %s", f, err.Error())
}
}
}
diff --git a/cmd/podman/system/prune.go b/cmd/podman/system/prune.go
index e09e2d5e5..5565ea2f9 100644
--- a/cmd/podman/system/prune.go
+++ b/cmd/podman/system/prune.go
@@ -113,15 +113,15 @@ func prune(cmd *cobra.Command, args []string) error {
func createPruneWarningMessage(pruneOpts entities.SystemPruneOptions) string {
if pruneOpts.All {
- return `WARNING! This will remove:
+ return `WARNING! This command removes:
- all stopped containers
- all networks not used by at least one container%s
- - all images without at least one container associated to them
+ - all images without at least one container associated with them
- all build cache
%s`
}
- return `WARNING! This will remove:
+ return `WARNING! This command removes:
- all stopped containers
- all networks not used by at least one container%s
- all dangling images
diff --git a/cmd/podman/system/service.go b/cmd/podman/system/service.go
index d6fe8837b..99a6b1e1e 100644
--- a/cmd/podman/system/service.go
+++ b/cmd/podman/system/service.go
@@ -74,7 +74,7 @@ func service(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
- logrus.Infof("using API endpoint: '%s'", apiURI)
+ logrus.Infof("Using API endpoint: '%s'", apiURI)
// Clean up any old existing unix domain socket
if len(apiURI) > 0 {
uri, err := url.Parse(apiURI)
@@ -120,7 +120,7 @@ func resolveAPIURI(_url []string) (string, error) {
case len(_url) > 0 && _url[0] != "":
return _url[0], nil
case systemd.SocketActivated():
- logrus.Info("using systemd socket activation to determine API endpoint")
+ logrus.Info("Using systemd socket activation to determine API endpoint")
return "", nil
case rootless.IsRootless():
xdg, err := util.GetRuntimeDir()