Skip to content

Commit c28fd3c

Browse files
Merge pull request #25966 from Luap99/start-rm
remote: don't print bogus error when starting container attached
2 parents 2b647bf + 0eac57e commit c28fd3c

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

pkg/domain/infra/abi/containers.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,12 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
958958
for i := range containers {
959959
ctr := containers[i]
960960

961+
removeContainer := func() {
962+
if _, _, err := ic.removeContainer(ctx, ctr.Container, entities.RmOptions{}); err != nil {
963+
logrus.Errorf("Removing container %s: %v", ctr.ID(), err)
964+
}
965+
}
966+
961967
if options.Attach {
962968
err = terminal.StartAttachCtr(ctx, ctr.Container, options.Stdout, options.Stderr, options.Stdin, options.DetachKeys, options.SigProxy, true)
963969
if errors.Is(err, define.ErrDetach) {
@@ -991,9 +997,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
991997
ExitCode: exitCode,
992998
})
993999
if ctr.AutoRemove() {
994-
if _, _, err := ic.removeContainer(ctx, ctr.Container, entities.RmOptions{}); err != nil {
995-
logrus.Errorf("Removing container %s: %v", ctr.ID(), err)
996-
}
1000+
removeContainer()
9971001
}
9981002
return reports, fmt.Errorf("unable to start container %s: %w", ctr.ID(), err)
9991003
}
@@ -1002,6 +1006,9 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
10021006
if err2 != nil {
10031007
logrus.Errorf("Waiting for container %s: %v", ctr.ID(), err2)
10041008
}
1009+
if ctr.AutoRemove() && !ctr.ShouldRestart(ctx) {
1010+
removeContainer()
1011+
}
10051012
reports = append(reports, &entities.ContainerStartReport{
10061013
Id: ctr.ID(),
10071014
RawInput: ctr.rawInput,
@@ -1038,9 +1045,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
10381045
}
10391046
report.Err = fmt.Errorf("unable to start container %q: %w", ctr.ID(), err)
10401047
if ctr.AutoRemove() {
1041-
if _, _, err := ic.removeContainer(ctx, ctr.Container, entities.RmOptions{}); err != nil {
1042-
logrus.Errorf("Removing container %s: %v", ctr.ID(), err)
1043-
}
1048+
removeContainer()
10441049
}
10451050
reports = append(reports, report)
10461051
continue

pkg/domain/infra/tunnel/containers.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,6 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
806806
logrus.Errorf("Failed to check if %s should restart: %v", ctr.ID, err)
807807
return
808808
}
809-
logrus.Errorf("Should restart: %v", shouldRestart)
810809

811810
if !shouldRestart && ctr.AutoRemove {
812811
removeContainer(ctr.ID, ctr.CIDFile)

test/system/045-start.bats

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,18 @@ load helpers
149149
run_podman rm -t 0 -f $ctrID $cname
150150
}
151151

152+
# Regression test for https://github.com/containers/podman/issues/25965
153+
# bats test_tags=ci:parallel
154+
@test "podman start attach with created --rm container" {
155+
local msg=c-$(safename)
156+
run_podman create --rm $IMAGE echo "$msg"
157+
cid="$output"
158+
159+
run_podman start -a $cid
160+
assert "$output" == "$msg" "attach printed the expected output"
161+
162+
# container must be removed on its own as it was created with --rm
163+
run_podman 1 container exists $cid
164+
}
165+
152166
# vim: filetype=sh

0 commit comments

Comments
 (0)