Home > Software design >  docker rm command returning different status code on different machine with same os
docker rm command returning different status code on different machine with same os

Time:07-20

I am trying to remove docker container if it exists. And I am checking success of this operation using it's exit code status. But it returns different exit code on different machine. Any idea what's going on here.

# First machine
$ docker ps -a
CONTAINER ID   IMAGE                                          COMMAND                  CREATED        STATUS        PORTS                                                                                                          NAMES
$ docker rm -f temp
Error: No such container: temp
$ echo $?
0
# os details
$ uname -a
Linux test-ubuntu 5.4.0-117-generic #132~18.04.1-Ubuntu SMP Thu Jun 2 23:36:48 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Second Machine (Failure Case)

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
$ docker rm -f temp
Error: No such container: temp
$ echo $?
1
$ uname -a
Linux test-jetson 4.9.253-tegra #1 SMP PREEMPT Sun Jan 2 01:44:04 PST 2022 aarch64 aarch64 aarch64 GNU/Linux

Third machine

$ docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
$ docker rm -f temp
Error: No such container: temp
$ echo $?
0
$ uname -a
Linux my-2nd-jetson 4.9.253-tegra #1 SMP PREEMPT Mon Jul 26 12:19:28 PDT 2021 aarch64 aarch64 aarch64 GNU/Linux

CodePudding user response:

This could be because the machines have different versions of docker. According to this github issue:

When using docker rm / docker container rm with the -f / --force option, attempts to remove non-existing containers should print a warning, but should return a zero exit code ("successful"). Currently, a non-zero exit code is returned, marking the removal as "failed";

But the issue has been fixed now, and with the latest versions you should not face this behaviour.

  • Related