summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-12-11 16:10:35 -0600
committerbaude <bbaude@redhat.com>2018-12-12 10:55:53 -0600
commit9786542620afea96d5eee2d05b7e1dec38a8235d (patch)
tree092e40048677955efe9a1e0d99c69c332d153726 /cmd/podman
parent8645df84dbb21f5988b46e6646bb0dd04fdb2b51 (diff)
downloadpodman-9786542620afea96d5eee2d05b7e1dec38a8235d.tar.gz
podman-9786542620afea96d5eee2d05b7e1dec38a8235d.tar.bz2
podman-9786542620afea96d5eee2d05b7e1dec38a8235d.zip
failed containers with --rm should remove themselves
when starting or running a container that has --rm, if the starting container fails (like due to an invalid command), the container should get removed. Resolves: #1985 Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/run.go5
-rw-r--r--cmd/podman/start.go14
2 files changed, 19 insertions, 0 deletions
diff --git a/cmd/podman/run.go b/cmd/podman/run.go
index a4b5c918e..20cb85347 100644
--- a/cmd/podman/run.go
+++ b/cmd/podman/run.go
@@ -116,6 +116,11 @@ func runCmd(c *cli.Context) error {
if strings.Index(err.Error(), "permission denied") > -1 {
exitCode = 126
}
+ if c.IsSet("rm") {
+ if deleteError := runtime.RemoveContainer(ctx, ctr, true); deleteError != nil {
+ logrus.Errorf("unable to remove container %s after failing to start and attach to it", ctr.ID())
+ }
+ }
return err
}
diff --git a/cmd/podman/start.go b/cmd/podman/start.go
index 8cf85405e..8bb386c68 100644
--- a/cmd/podman/start.go
+++ b/cmd/podman/start.go
@@ -1,11 +1,13 @@
package main
import (
+ "encoding/json"
"fmt"
"os"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
+ cc "github.com/containers/libpod/pkg/spec"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
@@ -132,6 +134,18 @@ func startCmd(c *cli.Context) error {
}
// Handle non-attach start
if err := ctr.Start(ctx); err != nil {
+ var createArtifact cc.CreateConfig
+ artifact, artifactErr := ctr.GetArtifact("create-config")
+ if artifactErr == nil {
+ if jsonErr := json.Unmarshal(artifact, &createArtifact); jsonErr != nil {
+ logrus.Errorf("unable to detect if container %s should be deleted", ctr.ID())
+ }
+ if createArtifact.Rm {
+ if rmErr := runtime.RemoveContainer(ctx, ctr, true); rmErr != nil {
+ logrus.Errorf("unable to remove container %s after it failed to start", ctr.ID())
+ }
+ }
+ }
if lastError != nil {
fmt.Fprintln(os.Stderr, lastError)
}