How can I delete a docker container with force ignore that means if there is no running docker container it should do nothing and if there is a running docker container with the name then it should stop and remove that container.
I am executing the following code to stop and remove the container.
docker rm -f CONTAINER_NAME || true
If there is a running container then everything works fine, however, if there is no container then the following error is thrown:
Error: No such container: CONTAINER_NAME
Is there something like --force ignore? I need this behaviour in order to include it in an automated Makefile.
try this exit code will be 1:
docker rm -f CONTAINER_NAME 2> /dev/null
this with exit code 0:
docker rm -f CONTAINER_NAME 2> /dev/null || true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With