Instead of just running another container
as we saw it many times before,
let's use the --help flag on Docker run
and let's see what we got here.
And you'll see there are actually a lot of things
you can configure when you run a container.
Now good news are, the vast majority of these options
will never really matter to you,
or if they do, you will know it, as dumb as that sounds.
There are a couple of options here
which we already saw though,
like the detach flag
or the publish flag for listening on a port
but there's one other important flag,
one other important setting which I wanna mention here.
And that's the --rm flag.
This automatically removes the container when it exits.
And this of course can be very useful
so that you don't manually have to clean up
all these stopped containers from time to time.
Instead you can simply add this to the run command
to ensure that whenever this container is stopped,
it's removed automatically.
And this makes a lot of sense here in my opinion.
So now we could pick us an image,
the latest one I have here,
and then execute docker run on that image
but we publish the internal port on port 3000.
Maybe we also run in detach mode
and I add --rm to ensure that this container
is always removed whenever we stop it.
If we now hit Enter,
this starts the container in detach mode.
If we type docker ps
we see the running container therefore.
And we can visit localhost 3000 and learn Docker in-depth.
And we can interact with that container as you learned it
but if you now stop that container,
you will see that it's also removed.
So if I stop this container here,
this again takes a short while,
but once it is stopped,
you will notice that if I then run docker ps -a,
it's not listed
because of the --rm flag
which automatically removes a container
when it's been stopped.
And it's not uncommon
that you use this flag for starting your containers,
especially if your container contains something like,
like such a node server,
where you often only stop your container
if your code changed
which also means that you need to rebuild your image
and therefore start a new container anyways.
So that would be a scenario
where removing a started container,
if it's shut down makes a lot of sense
because this is typically not a container
which you're ever going to restart.
We did this for demo purposes in the last lectures
but as I mentioned there already,
it's not uncommon that you don't restart
node server containers like this one.
So that's another useful piece of information
you should be aware of.
Being able to run a container with the --rm flag
to automatically remove it when it's been stopped.