1
00:00:02,140 --> 00:00:04,080
Now I'm back in the demo project

2
00:00:04,080 --> 00:00:05,410
we worked on before,

3
00:00:05,410 --> 00:00:09,170
and I'll bring up that built-in terminal again.

4
00:00:09,170 --> 00:00:10,980
But you can of course also open up

5
00:00:10,980 --> 00:00:14,680
a default terminal outside of Visual Studio code.

6
00:00:14,680 --> 00:00:17,800
And there we got various commands which we can run

7
00:00:17,800 --> 00:00:19,740
with help of the Docker command.

8
00:00:19,740 --> 00:00:20,850
And as I mentioned,

9
00:00:20,850 --> 00:00:24,070
if you for example run docker --help,

10
00:00:24,070 --> 00:00:27,860
you get a list of the built-in main commands

11
00:00:27,860 --> 00:00:29,710
you can run with Docker.

12
00:00:29,710 --> 00:00:33,480
And you see there are quite a lot of commands there.

13
00:00:33,480 --> 00:00:36,600
Well, good news is a lot of these commands

14
00:00:36,600 --> 00:00:41,600
will not really matter to you in the vast majority of cases.

15
00:00:41,930 --> 00:00:44,870
There also are some commands from the past

16
00:00:44,870 --> 00:00:48,170
where we nowadays have better ways of achieving something.

17
00:00:48,170 --> 00:00:51,603
But still, you see we have quite a lot of commands here.

18
00:00:53,020 --> 00:00:55,180
You can obviously read these descriptions

19
00:00:55,180 --> 00:00:57,070
to see what these commands do,

20
00:00:57,070 --> 00:00:59,990
but it will come down to a couple of core commands

21
00:00:59,990 --> 00:01:01,780
you should be aware of.

22
00:01:01,780 --> 00:01:05,550
In addition, there also are some commands which also

23
00:01:05,550 --> 00:01:09,470
could be replaced by other commands executed differently.

24
00:01:09,470 --> 00:01:12,700
In general, with Docker for some operations

25
00:01:12,700 --> 00:01:16,310
you have multiple ways of performing that operation.

26
00:01:16,310 --> 00:01:20,220
Now I wanna start with managing images and containers

27
00:01:20,220 --> 00:01:22,383
since that is what Docker is all about.

28
00:01:23,500 --> 00:01:25,640
And we already saw for example

29
00:01:25,640 --> 00:01:29,430
that you can list all containers by running docker ps.

30
00:01:29,430 --> 00:01:33,500
And this shows you all running containers by default.

31
00:01:33,500 --> 00:01:35,717
Now if you add -a,

32
00:01:35,717 --> 00:01:38,480
you see all containers you had in the past

33
00:01:38,480 --> 00:01:40,440
including the stopped containers

34
00:01:40,440 --> 00:01:42,760
which are not running anymore.

35
00:01:42,760 --> 00:01:46,640
As a side note, if you run docker ps --help,

36
00:01:46,640 --> 00:01:51,360
you see all available config options for docker ps.

37
00:01:51,360 --> 00:01:56,360
And here's the -a flag which we used to show all containers.

38
00:01:56,690 --> 00:02:00,250
So docker ps -a shows us all containers,

39
00:02:00,250 --> 00:02:03,110
including the containers we stopped.

40
00:02:03,110 --> 00:02:06,440
And one important thing you can also do with Docker

41
00:02:06,440 --> 00:02:09,620
is you can restart a stopped container.

42
00:02:09,620 --> 00:02:13,810
You don't always need to docker run a new container,

43
00:02:13,810 --> 00:02:15,290
because that's important.

44
00:02:15,290 --> 00:02:19,170
With docker run, you create a new container

45
00:02:19,170 --> 00:02:20,350
based on an image,

46
00:02:20,350 --> 00:02:24,010
and that new container is started thereafter.

47
00:02:24,010 --> 00:02:27,690
Sometimes that is what you want but sometimes it's not.

48
00:02:27,690 --> 00:02:31,380
If nothing changed about our application,

49
00:02:31,380 --> 00:02:34,440
about the dependencies and our source code,

50
00:02:34,440 --> 00:02:36,550
and our image didn't change,

51
00:02:36,550 --> 00:02:40,230
there is no need to create a brand new container.

52
00:02:40,230 --> 00:02:43,230
We can just restart an existing container.

53
00:02:43,230 --> 00:02:46,780
And for that we can just search for stopped containers

54
00:02:46,780 --> 00:02:48,610
with docker ps -a.

55
00:02:48,610 --> 00:02:51,850
Now you might see a different output than I do here

56
00:02:51,850 --> 00:02:55,150
because I'm also working with these containers off screen,

57
00:02:55,150 --> 00:02:59,330
deleting some which we'll learn later and adding new ones.

58
00:02:59,330 --> 00:03:02,620
But here you see my history of Docker containers

59
00:03:02,620 --> 00:03:04,430
I worked with recently.

60
00:03:04,430 --> 00:03:07,250
And if nothing changed about our code

61
00:03:07,250 --> 00:03:08,540
and about our Docker file,

62
00:03:08,540 --> 00:03:11,260
we can just grab let's say this one,

63
00:03:11,260 --> 00:03:14,420
the most recent one which exited

64
00:03:14,420 --> 00:03:18,890
and restart that with docker start.

65
00:03:18,890 --> 00:03:23,690
If we run docker start and then the container ID or name,

66
00:03:23,690 --> 00:03:26,690
this will bring the container back up.

67
00:03:26,690 --> 00:03:31,540
Now you'll see it starts the container in a different mode.

68
00:03:31,540 --> 00:03:36,040
It's not blocking the terminal as it did with docker run,

69
00:03:36,040 --> 00:03:39,580
but I can tell you this container is up and running.

70
00:03:39,580 --> 00:03:42,600
And you can verify by running docker ps

71
00:03:42,600 --> 00:03:46,720
without the -a flag to only see the running containers.

72
00:03:46,720 --> 00:03:49,003
And you should see this container here.

73
00:03:50,270 --> 00:03:55,270
And we can also visit localhost 3000 and reload there.

74
00:03:55,580 --> 00:03:59,070
And there our application is up and running,

75
00:03:59,070 --> 00:04:01,970
thanks to this restarted container.

76
00:04:01,970 --> 00:04:03,470
But again, as I mentioned,

77
00:04:03,470 --> 00:04:08,470
this restarted container is in this strange mode where,

78
00:04:08,770 --> 00:04:11,130
yes, it did start.

79
00:04:11,130 --> 00:04:13,990
But no, we're not really able to interact with it

80
00:04:13,990 --> 00:04:15,620
or to see the logs.

81
00:04:15,620 --> 00:04:17,930
Instead, it started this container

82
00:04:17,930 --> 00:04:20,190
and then returned to the terminal

83
00:04:20,190 --> 00:04:22,320
so that we could enter more commands.

84
00:04:22,320 --> 00:04:26,570
And as I mentioned, that's different to what docker run did.

85
00:04:26,570 --> 00:04:29,483
Well, that's something we're going to explore next.

