How to start a docker container and delete the container on exit

In this very quick article, I am sharing a command snippet that you probably need to run often. You want to start a docker container locally but you don’t want to leave anything leftover running or even the container itself after you exit.

Here is how you do it:

docker run -it --rm ubuntu:latest bash

-it

-i and -t are used together to allocate a tty for the docker container

–rm

Clean up the container after the process in the container exit. If you are running the bash, that’s when you exit the shell.

Submit a Comment

Your email address will not be published. Required fields are marked *