mirror of
https://github.com/containers/podman.git
synced 2025-07-03 17:27:18 +08:00
Merge pull request #25966 from Luap99/start-rm
remote: don't print bogus error when starting container attached
This commit is contained in:
@ -958,6 +958,12 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
|||||||
for i := range containers {
|
for i := range containers {
|
||||||
ctr := containers[i]
|
ctr := containers[i]
|
||||||
|
|
||||||
|
removeContainer := func() {
|
||||||
|
if _, _, err := ic.removeContainer(ctx, ctr.Container, entities.RmOptions{}); err != nil {
|
||||||
|
logrus.Errorf("Removing container %s: %v", ctr.ID(), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if options.Attach {
|
if options.Attach {
|
||||||
err = terminal.StartAttachCtr(ctx, ctr.Container, options.Stdout, options.Stderr, options.Stdin, options.DetachKeys, options.SigProxy, true)
|
err = terminal.StartAttachCtr(ctx, ctr.Container, options.Stdout, options.Stderr, options.Stdin, options.DetachKeys, options.SigProxy, true)
|
||||||
if errors.Is(err, define.ErrDetach) {
|
if errors.Is(err, define.ErrDetach) {
|
||||||
@ -991,9 +997,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
|||||||
ExitCode: exitCode,
|
ExitCode: exitCode,
|
||||||
})
|
})
|
||||||
if ctr.AutoRemove() {
|
if ctr.AutoRemove() {
|
||||||
if _, _, err := ic.removeContainer(ctx, ctr.Container, entities.RmOptions{}); err != nil {
|
removeContainer()
|
||||||
logrus.Errorf("Removing container %s: %v", ctr.ID(), err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return reports, fmt.Errorf("unable to start container %s: %w", ctr.ID(), err)
|
return reports, fmt.Errorf("unable to start container %s: %w", ctr.ID(), err)
|
||||||
}
|
}
|
||||||
@ -1002,6 +1006,9 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
|||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
logrus.Errorf("Waiting for container %s: %v", ctr.ID(), err2)
|
logrus.Errorf("Waiting for container %s: %v", ctr.ID(), err2)
|
||||||
}
|
}
|
||||||
|
if ctr.AutoRemove() && !ctr.ShouldRestart(ctx) {
|
||||||
|
removeContainer()
|
||||||
|
}
|
||||||
reports = append(reports, &entities.ContainerStartReport{
|
reports = append(reports, &entities.ContainerStartReport{
|
||||||
Id: ctr.ID(),
|
Id: ctr.ID(),
|
||||||
RawInput: ctr.rawInput,
|
RawInput: ctr.rawInput,
|
||||||
@ -1038,9 +1045,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
|||||||
}
|
}
|
||||||
report.Err = fmt.Errorf("unable to start container %q: %w", ctr.ID(), err)
|
report.Err = fmt.Errorf("unable to start container %q: %w", ctr.ID(), err)
|
||||||
if ctr.AutoRemove() {
|
if ctr.AutoRemove() {
|
||||||
if _, _, err := ic.removeContainer(ctx, ctr.Container, entities.RmOptions{}); err != nil {
|
removeContainer()
|
||||||
logrus.Errorf("Removing container %s: %v", ctr.ID(), err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
reports = append(reports, report)
|
reports = append(reports, report)
|
||||||
continue
|
continue
|
||||||
|
@ -806,7 +806,6 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
|||||||
logrus.Errorf("Failed to check if %s should restart: %v", ctr.ID, err)
|
logrus.Errorf("Failed to check if %s should restart: %v", ctr.ID, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logrus.Errorf("Should restart: %v", shouldRestart)
|
|
||||||
|
|
||||||
if !shouldRestart && ctr.AutoRemove {
|
if !shouldRestart && ctr.AutoRemove {
|
||||||
removeContainer(ctr.ID, ctr.CIDFile)
|
removeContainer(ctr.ID, ctr.CIDFile)
|
||||||
|
@ -149,4 +149,18 @@ load helpers
|
|||||||
run_podman rm -t 0 -f $ctrID $cname
|
run_podman rm -t 0 -f $ctrID $cname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Regression test for https://github.com/containers/podman/issues/25965
|
||||||
|
# bats test_tags=ci:parallel
|
||||||
|
@test "podman start attach with created --rm container" {
|
||||||
|
local msg=c-$(safename)
|
||||||
|
run_podman create --rm $IMAGE echo "$msg"
|
||||||
|
cid="$output"
|
||||||
|
|
||||||
|
run_podman start -a $cid
|
||||||
|
assert "$output" == "$msg" "attach printed the expected output"
|
||||||
|
|
||||||
|
# container must be removed on its own as it was created with --rm
|
||||||
|
run_podman 1 container exists $cid
|
||||||
|
}
|
||||||
|
|
||||||
# vim: filetype=sh
|
# vim: filetype=sh
|
||||||
|
Reference in New Issue
Block a user