summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/containers/start.go10
-rw-r--r--docs/source/markdown/podman-start.1.md4
-rw-r--r--pkg/domain/entities/containers.go1
-rw-r--r--pkg/domain/infra/abi/containers.go7
-rw-r--r--pkg/domain/infra/tunnel/containers.go8
-rw-r--r--test/system/045-start.bats43
6 files changed, 68 insertions, 5 deletions
diff --git a/cmd/podman/containers/start.go b/cmd/podman/containers/start.go
index 9b358db74..8d62dc12f 100644
--- a/cmd/podman/containers/start.go
+++ b/cmd/podman/containers/start.go
@@ -57,6 +57,8 @@ func startFlags(cmd *cobra.Command) {
flags.BoolVarP(&startOptions.Interactive, "interactive", "i", false, "Keep STDIN open even if not attached")
flags.BoolVar(&startOptions.SigProxy, "sig-proxy", false, "Proxy received signals to the process (default true if attaching, false otherwise)")
+ flags.BoolVar(&startOptions.All, "all", false, "Start all containers regardless of their state or configuration")
+
if registry.IsRemote() {
_ = flags.MarkHidden("sig-proxy")
}
@@ -79,7 +81,7 @@ func init() {
}
func validateStart(cmd *cobra.Command, args []string) error {
- if len(args) == 0 && !startOptions.Latest {
+ if len(args) == 0 && !startOptions.Latest && !startOptions.All {
return errors.New("start requires at least one argument")
}
if len(args) > 0 && startOptions.Latest {
@@ -88,6 +90,12 @@ func validateStart(cmd *cobra.Command, args []string) error {
if len(args) > 1 && startOptions.Attach {
return errors.Errorf("you cannot start and attach multiple containers at once")
}
+ if (len(args) > 0 || startOptions.Latest) && startOptions.All {
+ return errors.Errorf("either start all containers or the container(s) provided in the arguments")
+ }
+ if startOptions.Attach && startOptions.All {
+ return errors.Errorf("you cannot start and attach all containers at once")
+ }
return nil
}
diff --git a/docs/source/markdown/podman-start.1.md b/docs/source/markdown/podman-start.1.md
index 1822eab34..626e6e368 100644
--- a/docs/source/markdown/podman-start.1.md
+++ b/docs/source/markdown/podman-start.1.md
@@ -38,6 +38,10 @@ to run containers such as CRI-O, the last started container could be from either
Proxy received signals to the process (non-TTY mode only). SIGCHLD, SIGSTOP, and SIGKILL are not proxied. The default is *true* when attaching, *false* otherwise.
+#### **\-\-all**
+
+Start all the containers created by Podman, default is only running containers.
+
## EXAMPLE
podman start mywebserver
diff --git a/pkg/domain/entities/containers.go b/pkg/domain/entities/containers.go
index 7d074f89d..4707ced85 100644
--- a/pkg/domain/entities/containers.go
+++ b/pkg/domain/entities/containers.go
@@ -265,6 +265,7 @@ type ContainerExistsOptions struct {
// ContainerStartOptions describes the val from the
// CLI needed to start a container
type ContainerStartOptions struct {
+ All bool
Attach bool
DetachKeys string
Interactive bool
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index 6f8845f10..82f2a2424 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -693,14 +693,17 @@ func (ic *ContainerEngine) ContainerExecDetached(ctx context.Context, nameOrID s
func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []string, options entities.ContainerStartOptions) ([]*entities.ContainerStartReport, error) {
reports := []*entities.ContainerStartReport{}
var exitCode = define.ExecErrorCodeGeneric
- ctrs, rawInputs, err := getContainersAndInputByContext(false, options.Latest, namesOrIds, ic.Libpod)
+ ctrs, rawInputs, err := getContainersAndInputByContext(options.All, options.Latest, namesOrIds, ic.Libpod)
if err != nil {
return nil, err
}
// There can only be one container if attach was used
for i := range ctrs {
ctr := ctrs[i]
- rawInput := rawInputs[i]
+ rawInput := ctr.ID()
+ if !options.All {
+ rawInput = rawInputs[i]
+ }
ctrState, err := ctr.State()
if err != nil {
return nil, err
diff --git a/pkg/domain/infra/tunnel/containers.go b/pkg/domain/infra/tunnel/containers.go
index 4545d266b..de7f6f1d4 100644
--- a/pkg/domain/infra/tunnel/containers.go
+++ b/pkg/domain/infra/tunnel/containers.go
@@ -506,7 +506,7 @@ func startAndAttach(ic *ContainerEngine, name string, detachKeys *string, input,
func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []string, options entities.ContainerStartOptions) ([]*entities.ContainerStartReport, error) {
reports := []*entities.ContainerStartReport{}
var exitCode = define.ExecErrorCodeGeneric
- ctrs, err := getContainersByContext(ic.ClientCtx, false, false, namesOrIds)
+ ctrs, err := getContainersByContext(ic.ClientCtx, options.All, false, namesOrIds)
if err != nil {
return nil, err
}
@@ -514,9 +514,13 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
// There can only be one container if attach was used
for i, ctr := range ctrs {
name := ctr.ID
+ rawInput := ctr.ID
+ if !options.All {
+ rawInput = namesOrIds[i]
+ }
report := entities.ContainerStartReport{
Id: name,
- RawInput: namesOrIds[i],
+ RawInput: rawInput,
ExitCode: exitCode,
}
ctrRunning := ctr.State == define.ContainerStateRunning.String()
diff --git a/test/system/045-start.bats b/test/system/045-start.bats
new file mode 100644
index 000000000..ff818e51d
--- /dev/null
+++ b/test/system/045-start.bats
@@ -0,0 +1,43 @@
+#!/usr/bin/env bats -*- bats -*-
+
+load helpers
+
+@test "podman start --all - start all containers" {
+ # Run a bunch of short-lived containers, with different --restart settings
+ run_podman run -d $IMAGE /bin/true
+ cid_none_implicit="$output"
+ run_podman run -d --restart=no $IMAGE /bin/false
+ cid_none_explicit="$output"
+ run_podman run -d --restart=on-failure $IMAGE /bin/true
+ cid_on_failure="$output"
+
+ # Run one longer-lived one.
+ run_podman run -d --restart=always $IMAGE sleep 20
+ cid_always="$output"
+
+ run_podman wait $cid_none_implicit $cid_none_explicit $cid_on_failure
+
+ run_podman start --all
+ is "$output" ".*$cid_none_implicit" "started: container with no --restart"
+ is "$output" ".*$cid_none_explicit" "started: container with --restart=no"
+ is "$output" ".*$cid_on_failure" "started: container with --restart=on-failure"
+ if [[ $output =~ $cid_always ]]; then
+ die "podman start --all restarted a running container"
+ fi
+
+ run_podman rm $cid_none_implicit $cid_none_explicit $cid_on_failure
+ run_podman stop -t 1 $cid_always
+ run_podman rm $cid_always
+}
+
+@test "podman start --all with incompatible options" {
+ expected="Error: either start all containers or the container(s) provided in the arguments"
+ run_podman 125 start --all 12333
+ is "$output" "$expected" "start --all, with args, throws error"
+ if ! is_remote; then
+ run_podman 125 start --all --latest
+ is "$output" "$expected" "podman start --all --latest"
+ fi
+}
+
+# vim: filetype=sh