1
00:00:00,000 --> 00:00:02,600
Hello and welcome to this demo. In this demo,

2
00:00:02,600 --> 00:00:05,900
we're going to look at some of the basic Docker commands,

3
00:00:06,300 --> 00:00:10,400
some basic commands that are necessary for one to get started

4
00:00:10,400 --> 00:00:12,200
and in order to play around with Docker.

5
00:00:12,800 --> 00:00:16,500
So in the previous demo, we installed Docker following a

6
00:00:16,500 --> 00:00:20,100
set of instructions from the Docker documentation site and

7
00:00:20,100 --> 00:00:26,300
we ran a sample Docker hello-world Container and a Docker

8
00:00:26,300 --> 00:00:29,600
ubuntu image. In this demo,

9
00:00:29,600 --> 00:00:31,600
we're going to look, some other commands.

10
00:00:31,600 --> 00:00:36,000
So just to start with we will run the Docker will start with

11
00:00:36,000 --> 00:00:37,000
the docker run command.

12
00:00:37,000 --> 00:00:42,500
So the docker run command is used to run a Container from an image.

13
00:00:42,500 --> 00:00:47,300
So you need to specify an image name. To find out what images

14
00:00:47,300 --> 00:00:52,100
you can use go to the Docker Hub website and go to explore

15
00:00:52,100 --> 00:00:58,400
and you should be able to see a lot of default official images

16
00:00:58,400 --> 00:01:01,800
available like the hello-world that we just saw. Let's say

17
00:01:01,800 --> 00:01:07,000
you would like to try a centos. You could just

18
00:01:07,000 --> 00:01:10,800
do if you click on this you'll see the instructions on running

19
00:01:10,800 --> 00:01:13,900
the centos. So you could simply do as you can see here

20
00:01:13,900 --> 00:01:15,900
It just says, docker pull centos

21
00:01:16,200 --> 00:01:21,500
So you can simply do a docker run centos and that should

22
00:01:21,700 --> 00:01:25,300
first try and find if there's a centos image available

23
00:01:25,300 --> 00:01:29,400
locally. If not, it's just going to go out and

24
00:01:29,400 --> 00:01:34,600
download the latest image latest version of the centos image.

25
00:01:34,600 --> 00:01:41,400
[No audio]

26
00:01:41,400 --> 00:01:46,000
As you can see here the name if you simply specify a name

27
00:01:46,000 --> 00:01:52,800
like this as centos it's going to look at the library repository. Library is

28
00:01:52,800 --> 00:01:57,500
a default Docker repository, which has the official images.

29
00:01:58,600 --> 00:02:02,500
So if you go to the go back to the Docker Hub website, all

30
00:02:02,500 --> 00:02:08,100
the official images such as those that are available here

31
00:02:08,300 --> 00:02:12,500
can simply be downloaded with just the name of that particular image.

32
00:02:12,500 --> 00:02:17,800
On the other hand, if you develop your own images, for example, if I go to my

33
00:02:17,800 --> 00:02:22,200
dashboard and I have some images that I use here such as

34
00:02:22,200 --> 00:02:23,800
the ansible-playable etc.

35
00:02:24,000 --> 00:02:27,500
If I need to run any of these then I need to use the name

36
00:02:28,400 --> 00:02:31,400
in this particular format called as the first with the user ID.

37
00:02:31,400 --> 00:02:35,900
So mmumshad is my user ID and under and then followed by

38
00:02:35,900 --> 00:02:38,700
a forward slash and the name of the repository.

39
00:02:39,100 --> 00:02:43,500
So this it should you should use names in this format if

40
00:02:43,500 --> 00:02:50,600
you are using your own images or you could simply use the

41
00:02:50,600 --> 00:02:55,600
name directly, but that then these need to be official repositories

42
00:02:55,600 --> 00:02:57,500
that are supported by Docker.

43
00:02:59,100 --> 00:03:05,800
So I have this new image downloaded called Docker centos. Now

44
00:03:06,100 --> 00:03:09,700
it's not actually going to as you can see as I'm back to

45
00:03:09,700 --> 00:03:13,900
my prompt it didn't it ran but it exited immediately and

46
00:03:13,900 --> 00:03:17,000
that's because we didn't ask it to do anything.

47
00:03:17,000 --> 00:03:21,200
So it's just the centos image is just a base image for

48
00:03:21,200 --> 00:03:22,800
the CentOS operating system.

49
00:03:23,600 --> 00:03:27,900
As you know, Docker is used to run services and applications.

50
00:03:27,900 --> 00:03:32,500
So if you want to keep that Container alive, you need to be running something.

51
00:03:32,900 --> 00:03:37,800
So I'm just going to run it again

52
00:03:38,500 --> 00:03:41,600
and this time it won't take long because the image is already

53
00:03:41,600 --> 00:03:46,100
pulled and I'm going to say ask you to run the bash command

54
00:03:47,600 --> 00:03:51,200
and if I want to automatically be logged into the Docker

55
00:03:51,200 --> 00:03:55,200
Container when it's run I should be using the -it options.

56
00:03:55,200 --> 00:03:57,700
We look at what these options are in a bit.

57
00:03:59,300 --> 00:04:01,700
So now as you can see the prompt has changed.

58
00:04:01,700 --> 00:04:04,200
So what's happened is Docker

59
00:04:04,200 --> 00:04:07,000
ran this centos Container which is the CentOS operating

60
00:04:07,000 --> 00:04:12,300
system and then run the bash command and then it logged me

61
00:04:12,300 --> 00:04:18,700
in directly to the Container since I specified the -it options.

62
00:04:18,800 --> 00:04:21,000
So I'm now inside the Docker Container.

63
00:04:21,000 --> 00:04:26,100
If you look at this the prompt it says root@ and a unique

64
00:04:26,100 --> 00:04:29,000
ID. This is the unique ID for the Docker Container.

65
00:04:30,000 --> 00:04:32,600
Whereas earlier I was at the Docker prompt.

66
00:04:33,200 --> 00:04:37,300
Okay, so I'm going to just to check the operating system

67
00:04:37,300 --> 00:04:42,900
that I'm on I'm going to do a cat /etc/*release*

68
00:04:42,900 --> 00:04:49,300
and as you can see I am on the CentOS Linux OS so I'm inside the CentOS.

69
00:04:50,400 --> 00:04:54,500
Okay, so I'm going to exit now and I'm just going to clear my screen.

70
00:04:55,200 --> 00:05:00,300
So that's the first command so docker run and and image name

71
00:05:00,300 --> 00:05:01,800
will run a Docker Container.

72
00:05:02,200 --> 00:05:05,200
The next command that we're going to see is the ps command.

73
00:05:05,300 --> 00:05:08,500
I'm going to run the docker ps command. The docker ps command

74
00:05:08,500 --> 00:05:10,300
lists all the running Containers.

75
00:05:11,100 --> 00:05:14,200
In this case, I do not have a running Container because I just ran the

76
00:05:14,200 --> 00:05:18,300
centos, I logged into that centos, I ran a couple

77
00:05:18,300 --> 00:05:21,900
of commands, and then I exited and that actually took me out

78
00:05:21,900 --> 00:05:25,000
of the Container and the Container wasn't doing running any

79
00:05:25,000 --> 00:05:31,300
service. So Docker exited that Container. The docker ps command

80
00:05:31,300 --> 00:05:35,200
lists all the running Containers only. Now, I do not have any running Container.

81
00:05:35,200 --> 00:05:38,600
So what I'm going to do is I'm going to run the centos

82
00:05:38,600 --> 00:05:44,800
Container once again, so I'm going to say docker run centos and earlier

83
00:05:44,800 --> 00:05:46,900
I gave the bash command now,

84
00:05:46,900 --> 00:05:51,500
I'm just going to run the sleep command just going to sleep for 20 seconds.

85
00:05:52,100 --> 00:05:53,500
So the Container is going to come up.

86
00:05:54,100 --> 00:05:58,100
It's just going to sleep for 20 seconds and then it's just

87
00:05:58,100 --> 00:06:04,300
going to Shut down and then I want to run this in the background.

88
00:06:04,400 --> 00:06:09,000
So I'm just going to give it -d so that I get back to my

89
00:06:09,000 --> 00:06:14,000
terminal and as you can see, this is the Container ID and

90
00:06:14,000 --> 00:06:15,400
it just ran the Container.

91
00:06:15,400 --> 00:06:19,000
Now if I run the docker ps command, I will see that this

92
00:06:19,000 --> 00:06:21,200
is a Container ID, this is the image.

93
00:06:21,200 --> 00:06:25,300
It's running off of the command that is running is sleep

94
00:06:25,300 --> 00:06:27,200
20. So it's going to sleep for 20 seconds.

95
00:06:27,200 --> 00:06:29,100
It was created seven seconds ago.

96
00:06:29,500 --> 00:06:31,300
It's been up for six seconds

97
00:06:31,700 --> 00:06:35,800
and it says it's got a funny name called flamboyant_noyce.

98
00:06:36,800 --> 00:06:41,800
Okay now we asked it to just sleep for 20 seconds just to keep

99
00:06:41,800 --> 00:06:43,500
it alive for 20 seconds.

100
00:06:43,700 --> 00:06:47,700
So if I run the docker ps command now, probably it should have gone.

101
00:06:47,700 --> 00:06:50,800
Yes, so it's gone because it's slept for 20 seconds

102
00:06:50,800 --> 00:06:54,900
and then that was the end of that command and so since the

103
00:06:54,900 --> 00:06:58,600
command exited the Docker Container exited as well because

104
00:06:58,600 --> 00:07:04,300
it didn't have anything to run or any service running on it. Okay.

105
00:07:04,300 --> 00:07:07,900
So that's a quick example of docker ps command.

106
00:07:08,000 --> 00:07:12,000
Now if you'd like to see all the Containers you ran in the

107
00:07:12,000 --> 00:07:17,400
past and all the exited Containers especially so you could

108
00:07:17,400 --> 00:07:25,600
do a run a docker ps -a.
docker ps command with the -a option

109
00:07:26,200 --> 00:07:29,500
and you'll see all the all the Containers that exited.

110
00:07:29,800 --> 00:07:33,800
So the last one that we ran was the centos with

111
00:07:33,800 --> 00:07:37,600
the sleep command and it was created about a minute ago,

112
00:07:37,600 --> 00:07:41,800
and it exited about 54 seconds ago.

113
00:07:41,800 --> 00:07:43,000
Similarly before that,

114
00:07:43,000 --> 00:07:49,600
we ran the centos with the bash the first time and I was

115
00:07:49,600 --> 00:07:53,400
on it for about 3 minutes checking the OS etc and it

116
00:07:53,400 --> 00:07:55,300
was created about 4 minutes ago.

117
00:07:55,600 --> 00:07:59,600
Similarly, you can see all the previous Containers that we ran.

118
00:08:00,500 --> 00:08:06,000
So when you run a Container and it exits, the Container actually

119
00:08:06,000 --> 00:08:09,600
lives on the TestDrive.

120
00:08:10,500 --> 00:08:14,900
Now that we have seen how to list all the running Containers,

121
00:08:15,300 --> 00:08:18,300
let's look at another example, so I'm going to run the same

122
00:08:18,300 --> 00:08:24,600
command to run a centos but in this case, I'm going to sleep

123
00:08:24,600 --> 00:08:28,200
for around 2000 seconds and what this will mean is

124
00:08:28,200 --> 00:08:32,000
that my centos will run a centos Container and then

125
00:08:32,000 --> 00:08:34,299
it will sleep for 2000 seconds

126
00:08:35,500 --> 00:08:38,700
and so and after that it's going to exit. Now if I run the

127
00:08:38,700 --> 00:08:42,000
docker ps command now you should be able to see that so its

128
00:08:42,000 --> 00:08:46,900
up for 13 seconds and it's just going to be alive for 2000 seconds.

129
00:08:46,900 --> 00:08:50,400
Now for some reason if I want to stop or

130
00:08:50,400 --> 00:08:53,400
kill this Container right now. I could use the docker stop

131
00:08:53,400 --> 00:08:58,700
command. So I do a docker stop and then say serene_pasteur

132
00:08:59,900 --> 00:09:06,500
I could either provide the name of the Container or I could give the Container ID

133
00:09:07,500 --> 00:09:13,300
and when you do that, it takes a couple of seconds to stop

134
00:09:13,400 --> 00:09:17,000
or force kill that particular Docker Container.

135
00:09:17,000 --> 00:09:21,200
[No audio]

136
00:09:21,200 --> 00:09:24,800
Okay. Now if I do a docker ps, you can see that it's no longer

137
00:09:24,800 --> 00:09:29,700
there. If I do a docker ps -a, I will be able to see that

138
00:09:30,400 --> 00:09:32,800
the Container that I just ran at the top.

139
00:09:32,800 --> 00:09:36,100
It was created about a minute ago and it exited about nine

140
00:09:36,100 --> 00:09:39,500
seconds ago and you can see the exit code in here.

141
00:09:39,900 --> 00:09:43,400
So the exit code for the previous conditions are all 0 because

142
00:09:43,900 --> 00:09:45,800
they exited under normal conditions,

143
00:09:46,000 --> 00:09:48,900
but since I killed it using the stop command you can see

144
00:09:49,100 --> 00:09:51,800
exit code just 137 right here.

145
00:09:52,700 --> 00:09:57,100
Okay. So now I have a lot of Containers that I ran previously and

146
00:09:57,100 --> 00:09:59,100
I kind of want to clean it up.

147
00:09:59,100 --> 00:10:02,400
So what can I do to remove these Containers? For that,

148
00:10:02,400 --> 00:10:04,200
I could use the docker rm command.

149
00:10:04,200 --> 00:10:07,000
So I do a docker rm, going to start with the first one.

150
00:10:07,900 --> 00:10:09,700
I'm going to provide this Container ID.

151
00:10:09,700 --> 00:10:16,900
So I could either refer to the Containers with the Container ID or with the name right here.

152
00:10:17,200 --> 00:10:19,700
So in this case, I'm going to select this one.

153
00:10:19,700 --> 00:10:21,000
I'm going to provide the name.

154
00:10:22,800 --> 00:10:26,400
So I've removed two Containers and if I do a docker ps -a

155
00:10:26,400 --> 00:10:28,300
I will be able to see that those are gone.

156
00:10:28,300 --> 00:10:33,400
So that's what you should do to reclaim disk space.

157
00:10:34,300 --> 00:10:38,400
Similarly, I'm going to get rid of all of this. Now,

158
00:10:38,400 --> 00:10:40,800
I don't need to provide the entire Container ID.

159
00:10:41,900 --> 00:10:44,800
I could actually provide just a few the first few letters.

160
00:10:44,800 --> 00:10:49,300
So I say 345 and then I can provide multiple Container IDs

161
00:10:49,300 --> 00:10:54,100
in our names in the same command as well, so this one is 345.

162
00:10:54,100 --> 00:11:01,100
The next one is e0a, the next one is 773. So it's going to

163
00:11:01,100 --> 00:11:04,400
remove all of them at once. Now,

164
00:11:04,400 --> 00:11:05,700
we're on the docker ps command.

165
00:11:05,700 --> 00:11:08,000
I can see that all those three are gone.

166
00:11:08,000 --> 00:11:11,700
So this this is a way to remove the Docker Containers.

167
00:11:11,700 --> 00:11:14,200
[No audio]

168
00:11:14,200 --> 00:11:17,700
So I'm just going to clean up all that.

169
00:11:17,700 --> 00:11:21,700
[No audio]

170
00:11:21,700 --> 00:11:24,114
62 and 5b.

171
00:11:24,114 --> 00:11:26,531
[Author typing]

172
00:11:26,531 --> 00:11:31,970
So I don't have any Containers running or dead at the moment.

173
00:11:32,100 --> 00:11:34,700
So that's good. So I've cleaned up all of that.

174
00:11:34,800 --> 00:11:39,600
Now the image that I pulled which is the I've actually pulled

175
00:11:39,600 --> 00:11:43,700
three images so far. First the hello-world, then the ubuntu,

176
00:11:43,700 --> 00:11:48,900
and then the centos. Now to see the images that I currently

177
00:11:48,900 --> 00:11:52,200
have, I could run the docker images command.

178
00:11:53,700 --> 00:11:55,100
Then I can actually see the images.

179
00:11:55,100 --> 00:11:57,500
I actually pulled another one called busybox, which is a

180
00:11:57,500 --> 00:12:02,900
really really lightweight tool kit as you can call it.

181
00:12:03,800 --> 00:12:07,900
It's just one around 1.13 MB in size.

182
00:12:09,400 --> 00:12:11,400
So if you want to really, you know test something really

183
00:12:11,400 --> 00:12:14,200
small you could actually use this particular image.

184
00:12:14,700 --> 00:12:17,700
So now what do I do to get rid of these images?

185
00:12:17,700 --> 00:12:20,900
Let's say I pulled this for just to test them and I want to get rid of them.

186
00:12:22,200 --> 00:12:27,700
I could do a docker rm command followed by the name

187
00:12:27,700 --> 00:12:29,900
sorry docker rmi command.

188
00:12:29,900 --> 00:12:35,300
So rm is used for removing Containers rmi is used for removing images.

189
00:12:35,700 --> 00:12:41,400
So we do a docker rmi and then say busybox, that removes

190
00:12:41,400 --> 00:12:46,300
the busybox, then I do docker rmi and remove the ubuntu.

191
00:12:47,600 --> 00:12:54,100
That removes the ubuntu. So now I have two left and just to

192
00:12:54,100 --> 00:12:55,500
demo something real quick,

193
00:12:55,500 --> 00:12:59,300
I'm going to run a Container based off of centos

194
00:13:01,000 --> 00:13:04,100
and if it were a docker ps -a now I can see that there's

195
00:13:04,100 --> 00:13:09,200
a Container based on the centos image. Now, whatever the

196
00:13:09,200 --> 00:13:13,600
reason I did this is if I try to delete now, I can see the

197
00:13:13,600 --> 00:13:19,700
if I try to delete the Docker image for centos using the rmi command.

198
00:13:21,100 --> 00:13:25,500
It will actually fail telling me that this particular image

199
00:13:25,900 --> 00:13:28,500
is being used by a particular Container.

200
00:13:28,500 --> 00:13:33,100
So we actually have a Container dependent on this particular

201
00:13:33,100 --> 00:13:34,700
image as you can see here.

202
00:13:35,200 --> 00:13:40,300
So we need to get rid of all the Containers first before removing the image.

203
00:13:40,300 --> 00:13:49,800
So we're going to do a docker rm and 8e to remove the Container

204
00:13:50,400 --> 00:13:54,400
and we make sure the Container no longer exists and then

205
00:13:56,000 --> 00:14:02,000
we remove the image using docker rmi centos, now the image is gone.

206
00:14:02,000 --> 00:14:05,192
[Author typing]

207
00:14:05,200 --> 00:14:06,800
Similarly, we're going to remove

208
00:14:07,900 --> 00:14:16,900
the hello-world image. Okay, so we do not have any Containers

209
00:14:16,900 --> 00:14:21,500
and we do not have any images running at the moment.

210
00:14:23,600 --> 00:14:27,900
Okay, so that's some of the basic

211
00:14:29,400 --> 00:14:34,400
Docker commands, let me also show you one another command

212
00:14:35,400 --> 00:14:40,100
which is a pull. So if you do the docker pull earlier when

213
00:14:40,100 --> 00:14:45,600
we run the docker run command with ubuntu it first looks for an image locally.

214
00:14:45,600 --> 00:14:48,600
If not, it's going to go out and pull the image and then

215
00:14:48,600 --> 00:14:51,300
it's going to pull the image and immediately run that image

216
00:14:51,300 --> 00:14:55,600
run a Container with that image. Now if we don't want Docker

217
00:14:55,600 --> 00:14:58,700
to run immediately and if we just want to pull an image

218
00:14:58,900 --> 00:15:02,500
just to keep it so that later on if we were planning to run

219
00:15:02,500 --> 00:15:07,100
it and we don't want to spend time pulling the image.

220
00:15:07,300 --> 00:15:10,300
You could simply pull the image alone using the docker pull command.

221
00:15:10,400 --> 00:15:14,600
So you do a docker pull and say ubuntu and that goes out and

222
00:15:14,600 --> 00:15:19,100
pull the Docker image and stores it locally on the local

223
00:15:19,100 --> 00:15:25,200
system. Okay, so it's pulled the image. If I now run

224
00:15:25,200 --> 00:15:30,400
the docker images command I can see that ubuntu image is there.

225
00:15:30,400 --> 00:15:32,783
[Author typing]

226
00:15:32,800 --> 00:15:35,700
Okay, so there's one more thing to look at before we end

227
00:15:35,700 --> 00:15:40,200
this demo and that's running a command on a particular Container.

228
00:15:40,600 --> 00:15:45,200
Okay. So we're going to run a ubuntu Container.

229
00:15:45,500 --> 00:15:48,600
So we're going to do a docker run ubuntu and we're going

230
00:15:48,600 --> 00:15:53,300
to keep it alive for let's say a thousand a hundred seconds

231
00:15:53,900 --> 00:15:55,900
and we want it to run in the background

232
00:15:55,900 --> 00:15:58,800
so we get back to our prompt console.

233
00:15:59,200 --> 00:16:01,700
So we're going to do a run it in the background using the

234
00:16:01,700 --> 00:16:09,900
- d and so there it goes you could do a docker ps command.

235
00:16:09,900 --> 00:16:13,700
You can see that it's running and it's sleeping for 100 seconds.

236
00:16:14,200 --> 00:16:17,300
Now while a Docker Container is running like this,

237
00:16:17,300 --> 00:16:24,600
if you'd like to run a particular command on the currently

238
00:16:24,600 --> 00:16:28,200
executing Container, for example, if you'd like to see the

239
00:16:28,200 --> 00:16:31,700
contents of a particular file, which is inside the Container,

240
00:16:32,400 --> 00:16:35,900
you might want to run a cat command on a particular file.

241
00:16:36,300 --> 00:16:40,800
So to run a command inside a running Container first identify

242
00:16:40,800 --> 00:16:49,800
the Container you want to work with and then do a docker run. Sorry docker exec

243
00:16:49,800 --> 00:16:53,200
and provide the Container ID, in this case,

244
00:16:53,200 --> 00:16:57,000
this is a Container ID and then followed by the command that you wish around.

245
00:16:57,000 --> 00:17:02,000
So I'm just going to run the cat /etc/*release*

246
00:17:03,100 --> 00:17:06,598
file. So I'm just going to look at the release file to understand

247
00:17:06,598 --> 00:17:09,200
what version of the OS is running.

248
00:17:09,500 --> 00:17:16,500
So the exec command basically runs or executes and execute

249
00:17:16,500 --> 00:17:19,000
a command on a running Container.

250
00:17:19,000 --> 00:17:23,200
When I hit this it actually runs this particular command

251
00:17:23,300 --> 00:17:25,800
inside the Container and gives me an output.

252
00:17:25,800 --> 00:17:28,098
[No audio]

253
00:17:28,098 --> 00:17:32,200
So that's basically it for this demo.

254
00:17:32,300 --> 00:17:38,000
We just looked at some of the basic commands and the some

255
00:17:38,000 --> 00:17:39,400
of the additional parameters.

256
00:17:39,400 --> 00:17:42,400
We're going to look at look at them a little

257
00:17:42,400 --> 00:17:46,400
bit more in detail in the upcoming demos and lectures.

258
00:17:46,900 --> 00:17:48,200
So this is it for now.

259
00:17:49,400 --> 00:17:51,200
So these are some basic commands.

260
00:17:51,500 --> 00:17:53,300
So go ahead and play around with it.

261
00:17:54,100 --> 00:17:58,600
Thank you for your time and see you in the next lecture.
