1
00:00:00,305 --> 00:00:04,440
Instead of just running another container

2
00:00:05,388 --> 00:00:06,570
as we saw it many times before,

3
00:00:06,570 --> 00:00:09,557
let's use the --help flag on Docker run

4
00:00:09,557 --> 00:00:11,873
and let's see what we got here.

5
00:00:13,607 --> 00:00:15,863
And you'll see there are actually a lot of things

6
00:00:15,863 --> 00:00:18,580
you can configure when you run a container.

7
00:00:18,580 --> 00:00:22,020
Now good news are, the vast majority of these options

8
00:00:22,020 --> 00:00:24,683
will never really matter to you,

9
00:00:25,684 --> 00:00:29,190
or if they do, you will know it, as dumb as that sounds.

10
00:00:29,190 --> 00:00:30,716
There are a couple of options here

11
00:00:30,716 --> 00:00:32,600
which we already saw though,

12
00:00:32,600 --> 00:00:34,450
like the detach flag

13
00:00:34,450 --> 00:00:38,060
or the publish flag for listening on a port

14
00:00:38,060 --> 00:00:40,450
but there's one other important flag,

15
00:00:40,450 --> 00:00:43,680
one other important setting which I wanna mention here.

16
00:00:43,680 --> 00:00:46,910
And that's the --rm flag.

17
00:00:46,910 --> 00:00:51,090
This automatically removes the container when it exits.

18
00:00:51,090 --> 00:00:53,660
And this of course can be very useful

19
00:00:53,660 --> 00:00:56,150
so that you don't manually have to clean up

20
00:00:56,150 --> 00:00:59,050
all these stopped containers from time to time.

21
00:00:59,050 --> 00:01:01,770
Instead you can simply add this to the run command

22
00:01:01,770 --> 00:01:05,209
to ensure that whenever this container is stopped,

23
00:01:05,209 --> 00:01:07,200
it's removed automatically.

24
00:01:07,200 --> 00:01:09,860
And this makes a lot of sense here in my opinion.

25
00:01:09,860 --> 00:01:13,110
So now we could pick us an image,

26
00:01:13,110 --> 00:01:15,260
the latest one I have here,

27
00:01:15,260 --> 00:01:17,900
and then execute docker run on that image

28
00:01:17,900 --> 00:01:22,900
but we publish the internal port on port 3000.

29
00:01:23,160 --> 00:01:26,080
Maybe we also run in detach mode

30
00:01:26,080 --> 00:01:31,000
and I add --rm to ensure that this container

31
00:01:31,000 --> 00:01:34,560
is always removed whenever we stop it.

32
00:01:34,560 --> 00:01:35,710
If we now hit Enter,

33
00:01:35,710 --> 00:01:39,120
this starts the container in detach mode.

34
00:01:39,120 --> 00:01:40,630
If we type docker ps

35
00:01:40,630 --> 00:01:42,743
we see the running container therefore.

36
00:01:44,150 --> 00:01:49,150
And we can visit localhost 3000 and learn Docker in-depth.

37
00:01:50,300 --> 00:01:53,650
And we can interact with that container as you learned it

38
00:01:53,650 --> 00:01:56,060
but if you now stop that container,

39
00:01:56,060 --> 00:01:58,680
you will see that it's also removed.

40
00:01:58,680 --> 00:02:01,470
So if I stop this container here,

41
00:02:01,470 --> 00:02:03,850
this again takes a short while,

42
00:02:03,850 --> 00:02:05,940
but once it is stopped,

43
00:02:05,940 --> 00:02:10,940
you will notice that if I then run docker ps -a,

44
00:02:11,810 --> 00:02:13,040
it's not listed

45
00:02:13,040 --> 00:02:16,190
because of the --rm flag

46
00:02:16,190 --> 00:02:18,910
which automatically removes a container

47
00:02:18,910 --> 00:02:21,090
when it's been stopped.

48
00:02:21,090 --> 00:02:22,810
And it's not uncommon

49
00:02:22,810 --> 00:02:26,390
that you use this flag for starting your containers,

50
00:02:26,390 --> 00:02:29,660
especially if your container contains something like,

51
00:02:29,660 --> 00:02:31,320
like such a node server,

52
00:02:31,320 --> 00:02:34,030
where you often only stop your container

53
00:02:34,030 --> 00:02:35,640
if your code changed

54
00:02:35,640 --> 00:02:38,840
which also means that you need to rebuild your image

55
00:02:38,840 --> 00:02:41,950
and therefore start a new container anyways.

56
00:02:41,950 --> 00:02:43,240
So that would be a scenario

57
00:02:43,240 --> 00:02:45,610
where removing a started container,

58
00:02:45,610 --> 00:02:48,160
if it's shut down makes a lot of sense

59
00:02:48,160 --> 00:02:50,840
because this is typically not a container

60
00:02:50,840 --> 00:02:53,450
which you're ever going to restart.

61
00:02:53,450 --> 00:02:56,770
We did this for demo purposes in the last lectures

62
00:02:56,770 --> 00:02:58,710
but as I mentioned there already,

63
00:02:58,710 --> 00:03:01,400
it's not uncommon that you don't restart

64
00:03:01,400 --> 00:03:03,663
node server containers like this one.

65
00:03:04,670 --> 00:03:07,100
So that's another useful piece of information

66
00:03:07,100 --> 00:03:08,280
you should be aware of.

67
00:03:08,280 --> 00:03:12,900
Being able to run a container with the --rm flag

68
00:03:12,900 --> 00:03:15,983
to automatically remove it when it's been stopped.

