mirror of
https://github.com/containers/podman.git
synced 2025-06-24 03:08:13 +08:00
Merge pull request #2335 from mheon/enable_detach_rm
Enable --rm with --detach
This commit is contained in:
@ -399,9 +399,6 @@ func parseCreateOpts(ctx context.Context, c *cliconfig.PodmanCommand, runtime *l
|
|||||||
|
|
||||||
tty := c.Bool("tty")
|
tty := c.Bool("tty")
|
||||||
|
|
||||||
if c.Bool("detach") && c.Bool("rm") {
|
|
||||||
return nil, errors.Errorf("--rm and --detach cannot be specified together")
|
|
||||||
}
|
|
||||||
if c.Flag("cpu-period").Changed && c.Flag("cpus").Changed {
|
if c.Flag("cpu-period").Changed && c.Flag("cpus").Changed {
|
||||||
return nil, errors.Errorf("--cpu-period and --cpus cannot be set together")
|
return nil, errors.Errorf("--cpu-period and --cpus cannot be set together")
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
cc "github.com/containers/libpod/pkg/spec"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -124,12 +122,22 @@ func startCmd(c *cliconfig.StartValues) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ecode, err := ctr.Wait(); err != nil {
|
if ecode, err := ctr.Wait(); err != nil {
|
||||||
logrus.Errorf("unable to get exit code of container %s: %q", ctr.ID(), err)
|
if errors.Cause(err) == libpod.ErrNoSuchCtr {
|
||||||
|
// The container may have been removed
|
||||||
|
// Go looking for an exit file
|
||||||
|
ctrExitCode, err := readExitFile(runtime.GetConfig().TmpDir, ctr.ID())
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("Cannot get exit code: %v", err)
|
||||||
|
exitCode = 127
|
||||||
|
} else {
|
||||||
|
exitCode = ctrExitCode
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
exitCode = int(ecode)
|
exitCode = int(ecode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctr.Cleanup(ctx)
|
return nil
|
||||||
}
|
}
|
||||||
if ctrRunning {
|
if ctrRunning {
|
||||||
fmt.Println(ctr.ID())
|
fmt.Println(ctr.ID())
|
||||||
@ -137,18 +145,6 @@ func startCmd(c *cliconfig.StartValues) error {
|
|||||||
}
|
}
|
||||||
// Handle non-attach start
|
// Handle non-attach start
|
||||||
if err := ctr.Start(ctx); err != nil {
|
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, false); rmErr != nil {
|
|
||||||
logrus.Errorf("unable to remove container %s after it failed to start", ctr.ID())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if lastError != nil {
|
if lastError != nil {
|
||||||
fmt.Fprintln(os.Stderr, lastError)
|
fmt.Fprintln(os.Stderr, lastError)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user