YouTube2Text

Docker Explained for Absolute Beginners [2026] — Transcript

by KodeKloud · 8,858 words · 1,364 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Hello and welcome to the Docker for
  2. 0:01beginners course. My name is Mumshad
  3. 0:04Manambed and I'll be your instructor for
  4. 0:06this course.
  5. 0:07In this course, you will learn Docker
  6. 0:09through a series of lectures that use
  7. 0:11illustrations and animations and some
  8. 0:13fun analogies that simplify complex
  9. 0:15concepts.
  10. 0:17We have demos that will show you how to
  11. 0:18install and get started with Docker and
  12. 0:21most importantly, we have hands-on labs
  13. 0:23that you can access right in your
  14. 0:25browser. First, let's look at the
  15. 0:27objectives of this course.
  16. 0:29In this course, we'll first try to
  17. 0:30understand what containers are, what
  18. 0:32Docker is and why you might need it.
  19. 0:35We'll see how to run Docker container
  20. 0:36and how to build your own Docker image.
  21. 0:39We will see networking in Docker and how
  22. 0:41to use Docker compose, and what Docker
  23. 0:43registry is, how to deploy your own
  24. 0:45private registry and we then look at
  25. 0:48some of these concepts in depth and we
  26. 0:49try to understand how Docker really
  27. 0:51works under the hood.
  28. 0:53We look at Docker for Windows and Mac
  29. 0:55before finally getting a basic
  30. 0:57introduction to container orchestration
  31. 0:59tools like Docker Swarm and Kubernetes.
  32. 1:03Now, here's a quick note about hands-on
  33. 1:04labs. We provide real labs that you can
  34. 1:06access right in your browser, anywhere,
  35. 1:08anytime and as many times as you want.
  36. 1:11The labs give you instant access to a
  37. 1:13terminal, to a Docker host and an
  38. 1:14accompanying quiz portal.
  39. 1:16The quiz portal asks a set of questions
  40. 1:18such as exploring the environment and
  41. 1:20gathering information or you might be
  42. 1:22asked to perform an action such as run a
  43. 1:24Docker container or troubleshoot and fix
  44. 1:26an issue. The quiz portal then validates
  45. 1:28your work and gives you feedback
  46. 1:30instantly.
  47. 1:31Every lecture in the course is
  48. 1:33accompanied by such challenging
  49. 1:35interactive quizzes that makes learning
  50. 1:38Docker a fun activity.
  51. 1:40So, I hope you're as thrilled as I am to
  52. 1:42get started. So, let us begin.
  53. 1:46>> [music]
  54. 1:50>> We're going to start by looking at a
  55. 1:52high-level overview on why you need
  56. 1:54Docker. Let me start by sharing how I
  57. 1:56got introduced to Docker. In one of my
  58. 1:58previous projects, I had this
  59. 2:00requirement to set up an end-to-end
  60. 2:02application stack including various
  61. 2:04different technologies like a web server
  62. 2:06using Node.js, a database such as
  63. 2:08MongoDB, a messaging system like Redis,
  64. 2:11and an orchestration tool like Ansible.
  65. 2:13We had a lot of issues developing this
  66. 2:14application stack with all of these
  67. 2:16different components. First of all,
  68. 2:19their compatibility with the underlying
  69. 2:21OS was an issue. We had to make sure
  70. 2:23that all of these different services
  71. 2:25were compatible with of OS we were
  72. 2:27planning to use. There have been times
  73. 2:29when certain versions of the services
  74. 2:31were not compatible with the OS and
  75. 2:33we've had to go back and look at
  76. 2:35different operating systems that was
  77. 2:37compatible with all of these different
  78. 2:38services. Secondly, we had to check the
  79. 2:40compatibility between the services and
  80. 2:43the libraries and dependencies on the
  81. 2:44OS. We've had issues where one service
  82. 2:47requires one version of a dependent
  83. 2:48library, whereas another service
  84. 2:50requires another version.
  85. 2:52The architecture of our application
  86. 2:53changed over time. We've had to upgrade
  87. 2:55to newer versions of these components or
  88. 2:58change the database and so on.
  89. 3:00Every time something changed, we had to
  90. 3:02go through the same process of checking
  91. 3:04compatibility between these various
  92. 3:06components and the underlying
  93. 3:07infrastructure. This compatibility
  94. 3:09matrix issue is usually referred to as
  95. 3:12the matrix from hell.
  96. 3:14Next, every time we had a new developer
  97. 3:17on board, we found it really difficult
  98. 3:19to set up a new environment. The new
  99. 3:21developers had to follow a large set of
  100. 3:23instructions and run hundreds of
  101. 3:25commands to finally set up their
  102. 3:26environments. We had to make sure they
  103. 3:28were using the right operating system,
  104. 3:30the right versions of each of these
  105. 3:32components, and each developer had to
  106. 3:34set up all that by themselves each time.
  107. 3:37We also had different development, test,
  108. 3:39and production environments. One
  109. 3:41developer may be comfortable using one
  110. 3:43OS, and the others may be comfortable
  111. 3:45using another one. Also, we couldn't
  112. 3:47guarantee that the application that we
  113. 3:48were building would run the same way in
  114. 3:51different environments.
  115. 3:52All of these made our life in
  116. 3:54developing, building, and shipping the
  117. 3:55application really difficult. So, I
  118. 3:58needed something that could help us with
  119. 4:00the compatibility issue, and something
  120. 4:02that will let us modify or change these
  121. 4:05components without affecting the other
  122. 4:07components. And even modify the
  123. 4:09underlying operating systems as
  124. 4:10required.
  125. 4:12That search landed me on Docker.
  126. 4:14With Docker, I was able to run each
  127. 4:16component in a separate container with
  128. 4:19its own dependencies and its own
  129. 4:20libraries, all on the same VM and the
  130. 4:23OS, but within separate environments or
  131. 4:25containers.
  132. 4:26We had to build a Docker configuration
  133. 4:28once, and all our developers could now
  134. 4:30get started with a single Docker run
  135. 4:33command.
  136. 4:34Irrespective of what the underlying
  137. 4:36operating system they run, all they
  138. 4:37needed to do was to make sure they had
  139. 4:40Docker installed on their systems.
  140. 4:43And that's the problem Docker solves.
  141. 4:45Docker takes the matrix from hell, the
  142. 4:48tangle of services, libraries,
  143. 4:50dependencies, and operating systems, and
  144. 4:52packages each piece into its own
  145. 4:54self-contained container. The same setup
  146. 4:56runs the same way on every developer's
  147. 4:58laptop in test and in production. No
  148. 5:01more chasing version conflicts, no more
  149. 5:03pages of setup instructions for new
  150. 5:06developer, one Docker run command, and
  151. 5:08you're up.
  152. 5:11So, what are containers? Containers are
  153. 5:13completely isolated environments. They
  154. 5:15can have their own processes or
  155. 5:17services, their own network interfaces,
  156. 5:20their own mounts, just like virtual
  157. 5:21machines, except they all share the same
  158. 5:24OS kernel. We will look at what that
  159. 5:26means in a bit, but it's also important
  160. 5:29to note that containers are not new with
  161. 5:32Docker. Containers have existed for
  162. 5:34about 10 years now, and some of the
  163. 5:36different types of containers are LXC,
  164. 5:38LXD, LXCFS, and so on.
  165. 5:41Now, here's the thing that's actually
  166. 5:43changed since the early days. Docker
  167. 5:45started out using LXC under the hood,
  168. 5:48but Docker moved away from LXC back in
  169. 5:51version 0.9.0, and that was around 2014,
  170. 5:54and switched to its own library called
  171. 5:57libcontainer.
  172. 5:58libcontainer later became runC, which is
  173. 6:01the reference implementation of the OCI
  174. 6:03runtime specification. So, OCI stands
  175. 6:05for Open Container Initiative, and it's
  176. 6:07the open standard that defines how
  177. 6:09container runtimes and image formats
  178. 6:12should work. So, today when Docker runs
  179. 6:15a container, it's actually going through
  180. 6:17containerD and runC, not LXC, LXD, or
  181. 6:21LXCFS, which are still around as
  182. 6:24separate Linux container technologies,
  183. 6:26but Docker itself doesn't use them
  184. 6:27anymore.
  185. 6:29Now, setting up these low-level
  186. 6:30container environments is hard, and that
  187. 6:32is where Docker offers a high-level tool
  188. 6:35with several powerful functionalities,
  189. 6:38making it really easy for end users like
  190. 6:40us. And this is how Docker became so
  191. 6:43popular.
  192. 6:45To understand how Docker works, let us
  193. 6:47revisit some basic concepts of operating
  194. 6:49systems first. If you look at operating
  195. 6:51systems like Ubuntu, Fedora, openSUSE,
  196. 6:54or AlmaLinux and the rest, they all
  197. 6:57consist of two things:
  198. 6:59an OS kernel and a set of software. The
  199. 7:02OS kernel is responsible for interacting
  200. 7:04with the underlying hardware. The kernel
  201. 7:06remains the same, which is Linux in this
  202. 7:08case. It's the software above it that
  203. 7:11makes the operating systems different.
  204. 7:14This software may consist of a different
  205. 7:17user interface, drivers, compilers, file
  206. 7:19managers, developer tools, and so on.
  207. 7:22And you have a common Linux kernel
  208. 7:23shared across OSes and some custom
  209. 7:26software that differentiates operating
  210. 7:28systems from each other.
  211. 7:29Now, we said earlier that Docker
  212. 7:31containers share the underlying kernel.
  213. 7:33So, what does that mean?
  214. 7:35Sharing the kernel. Let's say we have a
  215. 7:37system with an Ubuntu OS with Docker
  216. 7:39installed on it.
  217. 7:41Docker can run any flavor of OS on top
  218. 7:44of it as long as they're all based on
  219. 7:46the same kernel, in this case Linux. So,
  220. 7:48if the underlying OS is Ubuntu, Docker
  221. 7:50can run a container based on another
  222. 7:52distribution like Debian, Fedora,
  223. 7:54openSUSE, or AlmaLinux.
  224. 7:57Each Docker container only has the
  225. 7:59additional software that we just talked
  226. 8:01about that makes these operating systems
  227. 8:03different. And Docker uses the
  228. 8:05underlying kernel of the Docker host,
  229. 8:08which works with all operating systems
  230. 8:10above.
  231. 8:10So, what is an OS that does not share
  232. 8:13the same kernel as these?
  233. 8:15Windows. So, you won't be able to run a
  234. 8:17Windows-based container on a Docker host
  235. 8:19with Linux on it. For that, you will
  236. 8:21need a Docker on a Windows server. Now,
  237. 8:23it is this when I say that most of my
  238. 8:25students go, "Hey, hold on. That's not
  239. 8:27true. They install Docker on Windows,
  240. 8:30they run a container based on Linux, and
  241. 8:32go, 'See, it's possible.'"
  242. 8:34Well, when you install Docker on Windows
  243. 8:36and run a Linux container on Windows,
  244. 8:38you're not really running a Linux
  245. 8:40container on Windows. Windows runs a
  246. 8:42Linux container on a Linux virtual
  247. 8:44machine under the host. So, it's really
  248. 8:47a Linux container on a Linux virtual
  249. 8:49machine on a Windows machine. So, we'll
  250. 8:52discuss more about this on the Docker on
  251. 8:54Windows or Mac
  252. 8:56lessons later in this course.
  253. 8:58Now, you might ask, "Isn't that a
  254. 8:59disadvantage then? Well, not being able
  255. 9:01to run another kernel on the OS?" Well,
  256. 9:04the answer is no, because unlike
  257. 9:05hypervisors, Docker is not meant to
  258. 9:08virtualize and run different operating
  259. 9:09systems and kernels on the same
  260. 9:11hardware.
  261. 9:12The main purpose of Docker is to package
  262. 9:15and containerize applications and to
  263. 9:17ship them and to run them anywhere,
  264. 9:19anytime, as many times as you want.
  265. 9:23Now, let us look at the difference
  266. 9:25between virtual machines and containers,
  267. 9:27something that we tend to do, especially
  268. 9:29those from a virtualization background.
  269. 9:31Now, in the case of Docker, we have the
  270. 9:33underlying hardware infrastructure, and
  271. 9:35then the OS, and then the Docker
  272. 9:38software itself installed on the OS.
  273. 9:41Docker then manages the containers that
  274. 9:43run with libraries and dependencies
  275. 9:44alone.
  276. 9:45In the case of virtual machines, we have
  277. 9:47the hypervisor like the ESX on the
  278. 9:49hardware, and then the virtual machines
  279. 9:51on them, and each virtual machine has
  280. 9:53its own OS inside it, and then the
  281. 9:56dependencies, and then the application.
  282. 9:58The overhead causes higher utilization
  283. 10:00of underlying resources as there are
  284. 10:02multiple virtual operating systems and
  285. 10:04kernels running.
  286. 10:06Virtual machines also consume higher
  287. 10:08disk space as each VM is heavy and is
  288. 10:10usually in gigabytes in size. Whereas
  289. 10:13Docker containers are lightweight and
  290. 10:14are usually in megabytes in size. This
  291. 10:17lets Docker containers boot up faster,
  292. 10:19usually in a matter of seconds, whereas
  293. 10:21VMs, as we know, take minutes to boot up
  294. 10:23because they need to boot up the entire
  295. 10:25operating system.
  296. 10:27It is also important to note that Docker
  297. 10:29has less isolation as more resources are
  298. 10:32shared between the containers, like the
  299. 10:34kernel, whereas VMs have complete
  300. 10:36isolation from each other. Now, since
  301. 10:38VMs don't rely on the underlying OS or
  302. 10:41kernel, you can run different types of
  303. 10:43applications built on different OSs such
  304. 10:45as
  305. 10:49Now, those are some of the differences
  306. 10:51between the two. And now, having said
  307. 10:53that, it's not an either container or
  308. 10:54virtual machine situation. It's
  309. 10:56containers and virtual machines. So,
  310. 10:58when you have large environments with
  311. 11:00thousands of applications, containers
  312. 11:02running on thousands of Docker hosts,
  313. 11:04you will often see containers
  314. 11:05provisioned on virtual Docker hosts.
  315. 11:08That way, we can use the advantages of
  316. 11:10both technologies. We get the benefits
  317. 11:11of virtualization to easily provision or
  318. 11:14decommission Docker hosts as required,
  319. 11:16and at the same time, you make use of
  320. 11:19the benefits of Docker to easily
  321. 11:20provision applications and quickly scale
  322. 11:22them as required. Remember that in this
  323. 11:25case, we will not be provisioning that
  324. 11:27many virtual machines as we might have
  325. 11:29before because earlier, we provisioned a
  326. 11:32virtual machine for each application.
  327. 11:34Now you might provision a virtual
  328. 11:36machine for hundreds or thousands of
  329. 11:38containers.
  330. 11:40There are a lot of containerized
  331. 11:42versions of applications readily
  332. 11:43available today. Most organizations have
  333. 11:45their products containerized and
  334. 11:47available in public Docker repository
  335. 11:49called Docker Hub. Docker Hub is the
  336. 11:50most popular registry, but there are
  337. 11:52many others, too. So, you have GitHub
  338. 11:54container registry, Google Artifact
  339. 11:56Registry, AWS ECR, and Azure Container
  340. 11:59Registry. You can find images of most
  341. 12:02common operating systems, databases, and
  342. 12:04other services and tools there. Once you
  343. 12:06identify the images that you need and
  344. 12:08you install Docker on your host,
  345. 12:10bringing up an application is as easy as
  346. 12:13running a Docker run command with the
  347. 12:14name of the image. So, running a Docker
  348. 12:16run Ansible command will run an instance
  349. 12:18of Ansible on the Docker host.
  350. 12:20Similarly, you can run an instance of
  351. 12:21MongoDB, Redis, and Node.js using the
  352. 12:24Docker run command. If you need to run
  353. 12:26multiple instances of the web service,
  354. 12:29you simply add as many instances as you
  355. 12:31need and configure a load balancer of
  356. 12:33some kind in the front.
  357. 12:35In case of one of the instances were
  358. 12:38to fail, simply destroy that instance
  359. 12:40and launch a new one. There are other
  360. 12:42solutions available for handling such
  361. 12:44cases that we will look at later in this
  362. 12:45course. For now, don't focus too much on
  363. 12:47the commands. We'll get to that in a
  364. 12:49bit.
  365. 12:50So, we've been talking about images and
  366. 12:52containers. Let's understand the
  367. 12:54difference between the two.
  368. 12:55An image is a package or a template,
  369. 12:58just like uh VM template that you might
  370. 13:00have worked with in the virtualization
  371. 13:01world.
  372. 13:02It is used to create one or more
  373. 13:04containers.
  374. 13:05Containers are running instances of
  375. 13:07images that are isolated and have their
  376. 13:09own environments and set of processes.
  377. 13:12As we have seen before, a lot of
  378. 13:14products have been Dockerized already.
  379. 13:16In case you cannot find what you're
  380. 13:17looking for, you could create your own
  381. 13:19image and push it to a Docker Hub
  382. 13:21repository, making it available for the
  383. 13:24public.
  384. 13:26If you look at it, traditionally,
  385. 13:28developers developed applications. Then
  386. 13:30they handed it over to the ops team to
  387. 13:31deploy and manage it in production
  388. 13:33environments.
  389. 13:34They did that by providing a set of
  390. 13:36instructions, information about how the
  391. 13:38host must be set up, what prerequisites
  392. 13:40are to be installed on the host, how the
  393. 13:42dependencies are to be configured, and
  394. 13:44so on. Since the ops team did not really
  395. 13:46develop the application on their own,
  396. 13:48they struggled with setting it up. When
  397. 13:50they had an issue, they worked with the
  398. 13:51developers to resolve it.
  399. 13:53With Docker, the developers and
  400. 13:55operations teams work hand in hand to
  401. 13:58transform the guide into a Dockerfile
  402. 14:01with both of their requirements.
  403. 14:03This Dockerfile is then used to create
  404. 14:05an image for their applications. This
  405. 14:08image can now run on any host with
  406. 14:10Docker installed on it, and it's
  407. 14:11guaranteed to run the same way
  408. 14:13everywhere.
  409. 14:14So, the ops team can now simply use the
  410. 14:17image to deploy the application, since
  411. 14:19the image was already working when the
  412. 14:21developer built it, and the operations
  413. 14:23have not modified it, it continues to
  414. 14:25work the same way when deployed in
  415. 14:27production.
  416. 14:28And that's one example of how a tool
  417. 14:30like Docker contributes to the DevOps
  418. 14:32culture.
  419. 14:34We will now see how to get started with
  420. 14:36Docker.
  421. 14:37Now, the way Docker is packaged today is
  422. 14:39a little different from the early days.
  423. 14:41So, let's clear that up before we
  424. 14:43install anything.
  425. 14:44In the past, Docker came in two
  426. 14:46editions, the community edition and the
  427. 14:49enterprise edition. The community
  428. 14:51edition was the free set of Docker
  429. 14:53products, and the enterprise edition was
  430. 14:55the certified supported container
  431. 14:57platform that came with enterprise
  432. 14:59add-ons like image management and image
  433. 15:01security, and a universal control plane
  434. 15:04for managing and orchestrating container
  435. 15:06runtimes. Of course, those came with a
  436. 15:09price.
  437. 15:10That split doesn't exist anymore. So,
  438. 15:12back in November 2019, Docker sold the
  439. 15:15enterprise edition to a company called
  440. 15:17Mirantis, and it's now sold as the
  441. 15:19Mirantis container runtime. That's a
  442. 15:22separate product from Docker.
  443. 15:24So, when you read older blog posts that
  444. 15:26mention Docker EE or Docker Enterprise
  445. 15:29Edition or compare Docker CE versus EE,
  446. 15:32that's the history. Those terms don't
  447. 15:34appear on Docker's site anymore.
  448. 15:38What you will see today is a free open
  449. 15:40source piece called Docker Engine plus a
  450. 15:43set of subscription tiers around it. So,
  451. 15:45Docker Engine itself, the CLI you type
  452. 15:47Docker and the daemon that does the
  453. 15:49work, Docker D is still free and open
  454. 15:52source.
  455. 15:53That's the part you install on a Linux
  456. 15:55server and that's what we'll use
  457. 15:57throughout this course.
  458. 15:59The subscription side wraps around
  459. 16:01Docker Desktop and Docker Hub and Docker
  460. 16:03offers four tiers. You have the
  461. 16:05personal, pro, team, and business.
  462. 16:08Personal is free and covers individuals,
  463. 16:10students, small teams, education, and
  464. 16:12non-commercial open source.
  465. 16:15Teams, pro, team, and business are paid.
  466. 16:19So, pro is for individual developers who
  467. 16:20want more from Docker Desktop and Docker
  468. 16:23Hub. Team for small teams that need
  469. 16:25collaboration features and business is
  470. 16:27for enterprises that need single
  471. 16:29sign-on, a hardened desktop, and image
  472. 16:32access management.
  473. 16:34Worth knowing if you work in a larger
  474. 16:36company because Docker Desktop on
  475. 16:38machines used for commercial work at
  476. 16:40companies above a certain size needs a
  477. 16:43paid subscription.
  478. 16:45So, for this course, the free path
  479. 16:47covers everything we need. The free
  480. 16:49Docker Engine is available on Linux,
  481. 16:51Mac, Windows, and on cloud platforms
  482. 16:53like AWS or Azure.
  483. 16:55In the upcoming demo, we'll take a look
  484. 16:57at how to install and get started with
  485. 16:59Docker on a Linux system. Now, if you
  486. 17:01are on Mac or Windows, you have two
  487. 17:03options, either install a Linux VM using
  488. 17:06VirtualBox or some kind of
  489. 17:07virtualization platform and then follow
  490. 17:09along with the upcoming demo, which is
  491. 17:12really the easiest way to get started
  492. 17:14with Docker. The second option is to
  493. 17:16install Docker Desktop for Mac or Docker
  494. 17:19Desktop for Windows, which are native
  495. 17:21applications. So, if that is really what
  496. 17:23you want, then check out the Docker for
  497. 17:25Mac and the Docker for Windows sections
  498. 17:27towards the end of this course to get
  499. 17:29yourselves set up and then head back
  500. 17:31here. Okay, so let's now head over to
  501. 17:34the demo where we'll take a look at how
  502. 17:36to install Docker on a Linux machine.
  503. 17:39Okay, we're now going to see how to
  504. 17:41install Docker on a
  505. 17:43Linux VM. So, here I have my Ubuntu VM.
  506. 17:47I'm logged into it and on the right I
  507. 17:49have a browser open. So, I'm going to go
  508. 17:50into docs.docker.com.
  509. 17:53And I'm going to go into manuals. And
  510. 17:56here on the left I have a few sections.
  511. 17:58So, there's Docker Desktop which we'll
  512. 18:00look at later. First, I'm going to go to
  513. 18:03Docker Engine and we'll see how to
  514. 18:05install Docker Engine on my Ubuntu VM.
  515. 18:07So, I'm going to keep it super simple in
  516. 18:09this first demo.
  517. 18:11Later on we're going to see what Docker
  518. 18:12Desktop is. So, Docker Desktop is
  519. 18:14basically
  520. 18:15a set of tools that are around Docker
  521. 18:17Engine. But, in this first demo I want
  522. 18:19to keep things super simple so you
  523. 18:20understand Docker without any anything
  524. 18:23else, right? So, we're just going to
  525. 18:24install Docker Engine. That's the first
  526. 18:26step. So, my system is Ubuntu so I'm
  527. 18:28going to select Ubuntu. And here I have
  528. 18:30my instructions on the right. So, let's
  529. 18:32read through this. So, at first it says
  530. 18:34to get started with Docker Engine on
  531. 18:36Ubuntu, make sure you meet the
  532. 18:37prerequisites. And there are
  533. 18:39a couple of prerequisites around
  534. 18:40firewall limitations. So, Docker is only
  535. 18:43compatible with IP tables and NFT and IP
  536. 18:44tables legacy.
  537. 18:46So, rules created with NFT are not
  538. 18:47supported. So, you can just read through
  539. 18:49those.
  540. 18:50Then the first requirement is that you
  541. 18:52need to be on a 64-bit version of one of
  542. 18:54these Ubuntu systems, right? So, these
  543. 18:56are the different versions available.
  544. 18:57Let's see where we are. So, if I go to
  545. 19:00my Ubuntu VM and run the cat command
  546. 19:02/etc/
  547. 19:04*release*.
  548. 19:06It's going to display the details of my
  549. 19:08VM. So, I can see that it's an Ubuntu
  550. 19:10distribution and it's 24.04
  551. 19:13noble version, right? And if I go here
  552. 19:15in the documentation page, I can see
  553. 19:16that this is a supported version. So,
  554. 19:18that's great. Next,
  555. 19:20I want to see what architecture I'm on.
  556. 19:22So, I should be on a 64-bit version of
  557. 19:23the OS.
  558. 19:25For this, we're going to run the D
  559. 19:27package command and the option print
  560. 19:30architecture.
  561. 19:31And I can see that I'm on an arm64
  562. 19:34version and I can see that that's
  563. 19:36supported. All right, so the
  564. 19:37prerequisites are good.
  565. 19:38Uh the next step is to uninstall any old
  566. 19:41versions.
  567. 19:42So, there are a bunch of packages that
  568. 19:43are going to get installed when you
  569. 19:44install Docker and we'll make sure that
  570. 19:46your system does not already have one of
  571. 19:47these. Now, remember,
  572. 19:49you want to be careful if you're running
  573. 19:50on an existing VM that is probably
  574. 19:52already in production with some other
  575. 19:54things already installed. So, you might
  576. 19:56want to be careful in that situation
  577. 19:57because this is a new VM. I'm just going
  578. 19:58to run this command and I can see that
  579. 20:01there are no packages that are installed
  580. 20:02already.
  581. 20:04The next step is to install using the
  582. 20:05app repository. So, the first thing is
  583. 20:07to set up the Docker's app repositories.
  584. 20:09I'm going to copy this command. As you
  585. 20:11can see, it's going to do an app update
  586. 20:12first and then install the certificates
  587. 20:14and then download the latest version of
  588. 20:17the Docker package
  589. 20:19and then make that executable and
  590. 20:21install it. So, I'm just going to copy
  591. 20:23that and run that those set of commands.
  592. 20:29Okay, when it's asking me for
  593. 20:30confirmation, I'm going to say yes.
  594. 20:38Okay, so that's done.
  595. 20:40And as the next step, we're going to
  596. 20:41install the latest version by running
  597. 20:43the app install command.
  598. 20:46Now, as you can see, it installs a bunch
  599. 20:47of things. So, there's the Docker CE,
  600. 20:48which is the community edition. There's
  601. 20:50the CE CLI. Then there's the containerd.
  602. 20:52We're going to discuss some of these
  603. 20:53later about Docker Compose and and build
  604. 20:56X plugins later in this course. So, for
  605. 20:57now, I'm just going to proceed with the
  606. 20:59installation.
  607. 21:07Okay, so that's completed.
  608. 21:09The next step is to verify that it's
  609. 21:11running. So, I'm going to copy this
  610. 21:12command.
  611. 21:13I'm going to run the system cuddle
  612. 21:15status docker command and it tells me
  613. 21:16that the status is now active and
  614. 21:18running.
  615. 21:20Perfect.
  616. 21:21Okay, I don't need to run this the next
  617. 21:23command. So, I'm just going to verify
  618. 21:24the installation is successful by
  619. 21:26running the hello world image. I'm going
  620. 21:27to copy this.
  621. 21:29Run that. So, in this case, what it's
  622. 21:31doing is it's pulling the hello world
  623. 21:33docker image from docker hub and it's
  624. 21:35going to run that
  625. 21:37an instance of that locally. So, here it
  626. 21:39is. It's downloaded the new image and
  627. 21:41there's a message hello from docker. And
  628. 21:43that means it's successfully installed.
  629. 21:46We now look at some of the docker
  630. 21:47commands.
  631. 21:48At the end of this lecture, you will go
  632. 21:50through a hands-on quiz where you will
  633. 21:52practice working with these commands.
  634. 21:54Let's start by looking at the docker run
  635. 21:56command. The docker run command is used
  636. 21:58to run a container from an image.
  637. 22:01Running the docker run engine x command
  638. 22:03will run an instance of the engine x
  639. 22:06application on the docker host if it
  640. 22:07already exists. If the image is not
  641. 22:09present on the host, it will go out to
  642. 22:11docker hub and pull that image down. But
  643. 22:14this is only done the first time. For
  644. 22:16subsequent executions, the same image
  645. 22:19will be reused. Now, one heads-up before
  646. 22:21we go further, docker hub limits
  647. 22:24unauthenticated pulls to 100 every 6
  648. 22:27hours per IP address.
  649. 22:29You log in with docker login, that goes
  650. 22:31up to 200 every 6 hours on the free
  651. 22:33personal tier and unlimited on the paid
  652. 22:36pro team or business plans. So, if you
  653. 22:38start hitting too many requests
  654. 22:40errors during this lesson, that's why
  655. 22:43login or use a paid account for CI work.
  656. 22:46The docker PS command lists all running
  657. 22:49containers and some basic information
  658. 22:51about them, such as the container ID,
  659. 22:53the name of the image we used to run the
  660. 22:55container, the current status, and the
  661. 22:56name of the container. Each container
  662. 22:58automatically gets a random ID and name
  663. 23:00created for it by docker, in this case
  664. 23:02silly sammich. To see all containers
  665. 23:05running or not use the dash a option.
  666. 23:07This outputs all running as well as
  667. 23:09previously stopped or exited containers.
  668. 23:12We'll talk about the command and port
  669. 23:14fields shown in this output later in
  670. 23:16this course.
  671. 23:17For now, let's just focus on the basic
  672. 23:19commands. To stop a running container
  673. 23:21use the Docker stop command, but you
  674. 23:23must provide either the container ID or
  675. 23:25the container name in the stop command.
  676. 23:27If you're not sure of the name, run the
  677. 23:29Docker PS command to get it. On success,
  678. 23:31you will see the name printed out and
  679. 23:33running Docker PS again will show no
  680. 23:35running containers. Running Docker PS A
  681. 23:38flag however, shows the container silly
  682. 23:40sammich and that it is in an exited
  683. 23:43state a few seconds ago. Now, what if we
  684. 23:45don't want this container lying around
  685. 23:47consuming space? What if we want to get
  686. 23:49rid of it for good? Use the Docker RM
  687. 23:51command to remove a stopped or exited
  688. 23:54container permanently. If it prints the
  689. 23:56name back, we are good. Run the Docker
  690. 23:58PS command again to verify that it is no
  691. 24:01longer present. Good. But, what about
  692. 24:04the Engine X image that was downloaded
  693. 24:06at first? We're not using that anymore.
  694. 24:08So, how do we get rid of that image? But
  695. 24:10first, how do we see a list of images
  696. 24:12present on our host? Run the Docker
  697. 24:14images command to see a list of
  698. 24:16available images and their sizes.
  699. 24:18On our host, we have four images: Engine
  700. 24:20X, Redis, Ubuntu, and Alpine. We will
  701. 24:23talk about tags later in this course
  702. 24:25when we discuss images. To remove an
  703. 24:27image that you no longer plan to use,
  704. 24:30run the Docker RMI command. Remember,
  705. 24:32you must make sure that no containers
  706. 24:34are running off of that image before
  707. 24:36attempting to remove the image. You must
  708. 24:38stop and delete all dependent containers
  709. 24:40to be able to delete an image.
  710. 24:43When we ran the Docker run command
  711. 24:44earlier, it downloaded the Ubuntu image
  712. 24:46as it couldn't find one locally. What if
  713. 24:48we simply want to download the image and
  714. 24:50keep it? So, when we run the Docker run
  715. 24:52command, we don't want to wait for it to
  716. 24:54download. Use the Docker pull command to
  717. 24:56only pull that image and not run the
  718. 24:58container. So, in this case, the docker
  719. 25:00pull
  720. 25:01uh Ubuntu command pulls the Ubuntu image
  721. 25:03and stores it on our host.
  722. 25:05The same Docker Hub rate limit caveat
  723. 25:08applies here. If you're pulling a lot,
  724. 25:10log in first. Let's look at another
  725. 25:12example. Say you were to run a Docker
  726. 25:14container from an Ubuntu image. When you
  727. 25:17run the docker uh run Ubuntu command, uh
  728. 25:19it runs an instance of the Ubuntu image
  729. 25:21and exits immediately. If you were to
  730. 25:23list the running containers, you
  731. 25:24wouldn't see the container running. If
  732. 25:26you list all containers, including those
  733. 25:28that are stopped, you will see that the
  734. 25:30new container you ran is in an exited
  735. 25:32state. Now, why is that? Unlike virtual
  736. 25:35machines, containers are not meant to
  737. 25:38host an operating system. Containers are
  738. 25:40meant to run a specific task or process,
  739. 25:43such as to host an instance of a web
  740. 25:45server or an application server or a
  741. 25:47database or simply to carry out some
  742. 25:50kind of computation or analysis task.
  743. 25:53Once the task is complete, the container
  744. 25:55exits. A container only lives as long as
  745. 25:57the process inside it is alive.
  746. 26:00If the web service inside the container
  747. 26:01is stopped or crashed, then the
  748. 26:03container exits. This is why, when you
  749. 26:06run a container from an Ubuntu image, it
  750. 26:08stops immediately. Because Ubuntu is
  751. 26:10just an image of an operating system
  752. 26:12that is used as the base image for other
  753. 26:15applications. There is no process or
  754. 26:17application running in it by default. If
  755. 26:20the image isn't running any service, as
  756. 26:22is the case with Ubuntu, you could
  757. 26:23instruct Docker to run a process with
  758. 26:25the docker run command.
  759. 26:27For example, a sleep command with a
  760. 26:29duration of 5 seconds. When the
  761. 26:31container starts, it runs the sleep
  762. 26:33command and goes into sleep for 5
  763. 26:34seconds, after which the sleep command
  764. 26:36exits and the container stops. What we
  765. 26:39just saw was executing a command when we
  766. 26:41run the container, but what if we would
  767. 26:42like to execute a command on a running
  768. 26:44container? For example, when I run
  769. 26:46the docker uh ps command, I can see that
  770. 26:49there is a running container which uses
  771. 26:51the Ubuntu image, and uh sleeps for 100
  772. 26:54seconds.
  773. 26:55Let's say I would like to see the
  774. 26:56contents of a file inside this
  775. 26:59particular container, I could use the
  776. 27:00Docker exec command to execute a command
  777. 27:03on my Docker container, in this case to
  778. 27:05print the contents of the {slash} etc.
  779. 27:07{slash} hosts file. That's also how you
  780. 27:09debug or poke around inside a running
  781. 27:11container, change a config, check a log,
  782. 27:13run a quick query.
  783. 27:15Finally, let's look at one more option
  784. 27:17before we head over to the practice
  785. 27:19exercises.
  786. 27:20I'm now going to run image I developed
  787. 27:22for a simple web application.
  788. 27:25The repository name is codecloud {slash}
  789. 27:27simple web app. It runs a simple web
  790. 27:30server that listens on port 8080.
  791. 27:32When you run a Docker run command like
  792. 27:34this, it runs in the foreground or in
  793. 27:36attached mode, meaning you will be
  794. 27:38attached to the console or the standard
  795. 27:40out of the Docker container, and you
  796. 27:43will see the output of the web service
  797. 27:44on your screen.
  798. 27:46You won't be able to do anything else on
  799. 27:47this console other than view the output
  800. 27:50until this Docker container stops. It
  801. 27:52won't respond to your inputs. Press the
  802. 27:54control C combination to stop the
  803. 27:56container, and the application hosted on
  804. 27:58the container exits, and you get back to
  805. 28:00your prompt. Another option is to run
  806. 28:02the Docker container in detached mode by
  807. 28:04providing the {dash} D option. This will
  808. 28:06run the Docker container in the
  809. 28:07background, and you will be back to your
  810. 28:09prompt immediately. The container will
  811. 28:11continue to run in the back end. Run the
  812. 28:13Docker ps command to view the running
  813. 28:15container. Now, if you would like to
  814. 28:17attach back to the running container
  815. 28:19later, run the Docker attach command and
  816. 28:21specify the name or ID of the Docker
  817. 28:23container. Now, remember, if you're
  818. 28:25specifying the ID of a container in any
  819. 28:27Docker command, you can simply provide
  820. 28:29the first few characters alone, just
  821. 28:31enough so it is different from the other
  822. 28:33container IDs on the host. In this case,
  823. 28:35I just typed the first five characters.
  824. 28:37Now, don't worry about accessing the UI
  825. 28:39of the web server. For now, we will look
  826. 28:41more into that in the upcoming lectures.
  827. 28:44For now, let's just understand the basic
  828. 28:46commands. We will now get our hands
  829. 28:48dirty with the Docker CLI. So, let's
  830. 28:51take a look at how to access the
  831. 28:53practice lab environments next.
  832. 28:56Okay, so the next thing that we're going
  833. 28:57to do is run a Docker container, run our
  834. 28:59first container. So, if you go to uh
  835. 29:02hub.docker.com,
  836. 29:05you'll find images that you can run. So,
  837. 29:07this is Docker Hub. This is Docker's
  838. 29:08central repository of all
  839. 29:11containers or all images that can be
  840. 29:13used to run containers. And if you see
  841. 29:15here, there are all sorts of images
  842. 29:16available. For example, for machine
  843. 29:18learning and AI, you have TensorFlow,
  844. 29:19Py- PyTorch.
  845. 29:21You have an image for Python. So, there
  846. 29:23are images available for almost anything
  847. 29:24that you can think of, for any versions
  848. 29:26of those softwares or applications.
  849. 29:29There are web servers, there's operating
  850. 29:31system uh base images like Alpine. Uh
  851. 29:33there are databases like Postgres,
  852. 29:35MySQL, MongoDB, and there's images for
  853. 29:38Grafana. So, almost anything that you
  854. 29:40can think of
  855. 29:41would probably have Docker image here.
  856. 29:43So, we're going to start simple. So,
  857. 29:45we'll go to operating systems, and we'll
  858. 29:46select one of these operating systems.
  859. 29:48So, there's Ubuntu, Debian. So, I'm
  860. 29:50going to go with Alpine. So, Alpine is a
  861. 29:52minimal
  862. 29:53Docker image
  863. 29:54based on Alpine Linux. So, Alpine Linux
  864. 29:56is a
  865. 29:58minimal operating system. And as you can
  866. 30:00see, its size is uh 3.6 MB. So, that's a
  867. 30:02super lightweight uh image. And all you
  868. 30:05need to do is copy this name from here,
  869. 30:08and we're going to run an instance of
  870. 30:10this image. So, back in my terminal, I'm
  871. 30:11going to run a Docker run command and
  872. 30:14paste the name of the image, which is
  873. 30:16Alpine. And the first time that I'm
  874. 30:18running this, it's going to download the
  875. 30:21uh layers of the image. And because it's
  876. 30:23so small, it's less than 5 MB, it's
  877. 30:24downloaded that in a matter of seconds.
  878. 30:27So, I now have the image locally, and
  879. 30:28it's already run it. Now, because this
  880. 30:30is an operating systems image, it's a
  881. 30:32base image, it doesn't have any
  882. 30:33application running on it currently. So,
  883. 30:35it just exits immediately, which is why
  884. 30:37I'm not able to see that, and I'm back
  885. 30:38on my terminal.
  886. 30:40So, I could run commands inside this
  887. 30:41container. So, I could run the docker
  888. 30:44run command again and I can
  889. 30:47run a command such as cat /etc/
  890. 30:50star release star. So, it's going to
  891. 30:52print So, there is nothing much I could
  892. 30:54do with it. What I could do is maybe run
  893. 30:57an application or a program that's
  894. 30:58inside the image already. So, I'll
  895. 31:01probably run a sleep command and sleep
  896. 31:03for say 10 seconds. And what's going to
  897. 31:05happen is it's going to create container
  898. 31:08from the image and then it's going to
  899. 31:10invoke the sleep command and it's going
  900. 31:11to sleep for 10 seconds. And for those
  901. 31:13for that 10 seconds, I'm going to be on
  902. 31:15on the terminal and now I'm Now, it's
  903. 31:16done and I'm back. Now, another thing
  904. 31:17that we could do is maybe we can explore
  905. 31:19another application maybe like a a web
  906. 31:22server. So, if I go back to the hub and
  907. 31:24if I go to web servers, I have a bunch
  908. 31:26of different web servers here. I'm just
  909. 31:27going to pick engine X for now and you
  910. 31:30can see that there are all sorts of
  911. 31:31different versions of engine X available
  912. 31:33here. There's slim versions and alpine
  913. 31:35versions and for now I'm just going to
  914. 31:37be look more into tags and versions
  915. 31:39later in the course. For now, I'm just
  916. 31:40going to copy the name from here. I'm
  917. 31:42going to run an instance of the engine X
  918. 31:44container. And again, what it's going to
  919. 31:47do now is it's going to pull the images
  920. 31:48needed to run an instance locally. So,
  921. 31:50it's going to do that and this is a
  922. 31:52slightly heavier image. So, it's about
  923. 31:5434 MB. So, it's going to download that
  924. 31:56and it's downloaded that and it's
  925. 31:57immediately run the engine X web server.
  926. 31:59So, the engine X web server is now
  927. 32:01running
  928. 32:02on on this host.
  929. 32:05Okay, we'll now see how to run a
  930. 32:06container in the background. So, earlier
  931. 32:08when I ran the docker run engine X
  932. 32:10command,
  933. 32:12it immediately started the engine X
  934. 32:14container on the foreground. So, I'm
  935. 32:15kind of in that stuck in that terminal.
  936. 32:18To get out of it, I'm going to do
  937. 32:19control C and now now I'm back to my
  938. 32:21terminal, but it's also killed that
  939. 32:23server as you can see here. So, the
  940. 32:25solution to that is to run it in the
  941. 32:27background. So, I'm going to do a docker
  942. 32:28run engine X, but I'm also going to add
  943. 32:30a {dash}d flag and what and what that's
  944. 32:33going to do is it's going to run the
  945. 32:34container in the background. So, now
  946. 32:36it's running, and this is the container
  947. 32:39ID. This is This is a long format of the
  948. 32:41ID, but you can refer to the container
  949. 32:43with the short form as well.
  950. 32:45Now, to list the running containers, you
  951. 32:47could do a docker PS command, and it
  952. 32:49lists all the running containers. As you
  953. 32:50can see here, this is the first
  954. 32:51container, and this is the ID. This is
  955. 32:53the short form of the ID, which is the
  956. 32:55first part of this long form ID that you
  957. 32:57see here. The image is nginx. It has an
  958. 33:00internal entry point command that it's
  959. 33:02run to run the server itself. It's been
  960. 33:05up for 21 seconds, and it's exporting
  961. 33:08port 80. So, the actual server itself is
  962. 33:10running on port 80. Again, we'll see
  963. 33:12later how to access this web server. And
  964. 33:14then it's also got a a funny name to it.
  965. 33:16It's called adoring uh Zukowski. And
  966. 33:20every container kind of gets this
  967. 33:23kind of nickname. So,
  968. 33:25next, to stop this container, you could
  969. 33:27do a docker stop command, and either
  970. 33:29specify this container ID or this name,
  971. 33:31or just even just the first four
  972. 33:32characters of this ID. Anything that can
  973. 33:34uniquely identify this container. So,
  974. 33:36I'm going to do a docker stop dbb4, and
  975. 33:38it's going to return the same ID that I
  976. 33:40gave. That means it's killed. So, if I
  977. 33:42do a docker PS command, I no longer see
  978. 33:44any container running. Now, how do I see
  979. 33:47the killed containers? So, I could do a
  980. 33:49docker PS, and do a {dash} A to list all
  981. 33:51containers, and now I see
  982. 33:53all the containers that I have run. So,
  983. 33:56the Alpine containers that I ran earlier
  984. 33:57with the sleep commands, all of them are
  985. 33:59here. And then I also see the latest
  986. 34:01container that I just ran, which exited
  987. 34:02about a minute ago, and it's just been
  988. 34:0414 seconds that it's exited. So, now how
  989. 34:08do I get rid of all of these? I have all
  990. 34:10of these containers that are in an
  991. 34:11exited state. That's just staying there.
  992. 34:13They're just living on my system. How do
  993. 34:14I delete and get rid of them? For that,
  994. 34:16I could do a docker RM command.
  995. 34:18So, I do a docker RM, and then specify
  996. 34:20the name of the container.
  997. 34:22And this is again again going to go
  998. 34:24ahead with just the first four letters,
  999. 34:25or I could provide
  1000. 34:27multiple containers at the same time.
  1001. 34:28So, I could do af6a.
  1002. 34:31That's the first container, and then I
  1003. 34:32have this 6F, that's the second
  1004. 34:34container. And then there's the 2E0E,
  1005. 34:37that's the third one. So, we're going to
  1006. 34:38run all of that and it's going to remove
  1007. 34:40all of them at once.
  1008. 34:42Now, when I do a docker ps -a, I see
  1009. 34:44that there's these many remaining. And I
  1010. 34:47can just go ahead and uh remove all of
  1011. 34:48them one after the other.
  1012. 34:51Okay, now we're going to look at images.
  1013. 34:53So, when we ran the docker run command
  1014. 34:56earlier, say docker run nginx,
  1015. 35:00we learned that it downloaded the docker
  1016. 35:03image for nginx
  1017. 35:05web server and it it ran it. Now, I
  1018. 35:08could run the docker images command to
  1019. 35:10view the images. So, currently I have
  1020. 35:12two of them. I have the Alpine latest,
  1021. 35:14which we downloaded earlier, and as you
  1022. 35:16can see the size of it's less than 5 MB,
  1023. 35:18and then you have the nginx image, which
  1024. 35:20is about 64 MB. Now, to delete these
  1025. 35:22images, I could run the docker rmi
  1026. 35:25command. So, to delete the containers,
  1027. 35:27it's the rm command, and to delete
  1028. 35:28images, it's the rmi command. So, I'm
  1029. 35:30going to do a docker rmi and then
  1030. 35:32specify the name of the image. In this
  1031. 35:34case, it's Alpine uh latest. And if I
  1032. 35:36just type Alpine and hit a tab, it's
  1033. 35:38going to auto-fill for me.
  1034. 35:40When I run it, it says it's deleted. So,
  1035. 35:42it first untags the image and then then
  1036. 35:44deletes it. And it returns the ID of
  1037. 35:47that uh image. So, if I do a docker
  1038. 35:48images again,
  1039. 35:50I see that
  1040. 35:52it's gone. Now, if I try to delete the
  1041. 35:54nginx image, I'm going to do a docker
  1042. 35:56rmi command again and then specify
  1043. 35:58nginx, then hit enter. It now says that
  1044. 36:01uh there is an error and it says unable
  1045. 36:02to delete the nginx image because
  1046. 36:05there's a container that is using it,
  1047. 36:06that's referencing it. So, if you look
  1048. 36:08here, uh earlier if you means this
  1049. 36:09information section here, it says U
  1050. 36:11means in use. So, it's just giving you a
  1051. 36:13hint here that this image is already in
  1052. 36:15use.
  1053. 36:16So, if we look at the docker ps command,
  1054. 36:18we see that there's nothing running. So,
  1055. 36:19there's no running container that's
  1056. 36:21using this image, but if you do a docker
  1057. 36:22ps -a command, we'll see all the exited
  1058. 36:25images as well. And then here we see
  1059. 36:27that there's this
  1060. 36:28container that's using the engine x
  1061. 36:29image, which is why we're unable to
  1062. 36:31delete that image. So, first we need to
  1063. 36:33remove the container, so I'm going to do
  1064. 36:34a docker rm 292e. That's the first four
  1065. 36:37characters of the container ID.
  1066. 36:39So, I'm now going to verify that there
  1067. 36:40are no containers running or exited
  1068. 36:42that's using this image. And now I'm
  1069. 36:44going to do a docker
  1070. 36:45rmi
  1071. 36:47engine x
  1072. 36:48command, and
  1073. 36:49that should ideally remove the image.
  1074. 36:52So, now I'm in a fully clean state. So,
  1075. 36:54if I do a docker ps, docker ps -a, or
  1076. 36:58docker images, I don't see any anything
  1077. 37:01whatsoever.
  1078. 37:02Another command that could come handy if
  1079. 37:04you have a lot of containers and a lot
  1080. 37:05of images, and if you're just playing
  1081. 37:07around,
  1082. 37:08is the docker system prune command. So,
  1083. 37:11if you run the docker system prune
  1084. 37:12command, what it's going to do is going
  1085. 37:14to it's going to stop all the running
  1086. 37:15containers,
  1087. 37:16and it's going to remove all the stopped
  1088. 37:18containers, it's going to remove all the
  1089. 37:19networks uh not used by at least one
  1090. 37:21container, it's going to remove all
  1091. 37:23dangling images, and remove unused build
  1092. 37:25cache. So, it's going to kind of clear
  1093. 37:26out your system. So, if you are playing
  1094. 37:28around in a development environment, and
  1095. 37:29if you have a lot of running containers
  1096. 37:31and images, and if you want to kind of
  1097. 37:32clean out your system, you could run
  1098. 37:33this docker system prune command, and
  1099. 37:34it's just going to go through and delete
  1100. 37:36and remove all the containers and images
  1101. 37:38that are not used. And in this case,
  1102. 37:40because I didn't have any containers, it
  1103. 37:42says total reclaimed space is zero
  1104. 37:43bytes, but if you did have some, it's
  1105. 37:45going to help you reclaim space.
  1106. 37:48We will now look at some of the other
  1107. 37:50docker run commands.
  1108. 37:51In this first part, let's talk about
  1109. 37:53image tags. We learned that we could run
  1110. 37:55a Redis container with a simple run
  1111. 37:57command, which gives us the latest
  1112. 37:59version of Redis, currently version
  1113. 38:018.6.1.
  1114. 38:03But what if uh we want to run another
  1115. 38:05version, like say an older uh version
  1116. 38:07such as 7.4? Well, you specify the
  1117. 38:10version separated by a colon. This is
  1118. 38:11called a tag. In that case, docker pulls
  1119. 38:14an image of the 7.4 version of Redis and
  1120. 38:17runs that. Also notice that if you don't
  1121. 38:19specify any tag, uh like in the first
  1122. 38:22command, Docker considers the default
  1123. 38:24tag to be latest. The latest tag points
  1124. 38:27to the latest version of that software,
  1125. 38:29which is governed by the authors of that
  1126. 38:31software. So, as a user, how do you find
  1127. 38:33information about these versions and
  1128. 38:35what is latest? Over at Docker Hub,
  1129. 38:38look up an image and you'll find all the
  1130. 38:40supported tags in its description. Each
  1131. 38:42version of the software can have
  1132. 38:43multiple short and long tags associated
  1133. 38:46with it. For example, version 8.6.1 also
  1134. 38:49carries the latest tag today. Now, every
  1135. 38:52time we pull a new version of an image,
  1136. 38:54Docker stores it on the host as a
  1137. 38:56separate entry. So, if I pulled both
  1138. 38:58Redis 8 6.1 and Redis 7.4 earlier,
  1139. 39:02they're both sitting there on my host.
  1140. 39:04To see all the images I have locally, I
  1141. 39:06run the Docker images command and it
  1142. 39:08gives me a table, the repository, the
  1143. 39:10tag, and the image ID for each one. And
  1144. 39:14if I want to clean up a specific version
  1145. 39:16that I no longer need, I run Docker RMI
  1146. 39:19followed by the exact tag. For example,
  1147. 39:22Docker RMI Redis 7.4.
  1148. 39:25That removes just that tagged image and
  1149. 39:27leaves the other versions alone.
  1150. 39:30Now, one quick note on the latest tag
  1151. 39:32before we move on. The latest tag is
  1152. 39:34convenient for quick experiments and
  1153. 39:36trying things out, but in production,
  1154. 39:38you should always pin to a specific tag,
  1155. 39:41something like Redis 7
  1156. 39:43for Alpine.
  1157. 39:45The reason is that latest is a moving
  1158. 39:47target. The day you redeploy, the image
  1159. 39:49authors may have pushed a new version
  1160. 39:52and your container quietly upgrades
  1161. 39:53under you, sometimes with breaking
  1162. 39:55changes. A pinned tag gives you the
  1163. 39:58exact same image every time and you
  1164. 40:00decide when to bump the version, not the
  1165. 40:02upstream maintainers.
  1166. 40:05Now, let's look at inputs. I have a
  1167. 40:07simple prompt application that, when
  1168. 40:09run, asks for my name. And on entering
  1169. 40:11my name, it prints a welcome message. If
  1170. 40:14I were to dockerize this application and
  1171. 40:16run it as a Docker container, it
  1172. 40:18wouldn't wait for the prompt. It just
  1173. 40:20prints whatever the application is
  1174. 40:21supposed to print on standard out.
  1175. 40:23That's because by default, the Docker
  1176. 40:24container does not listen to standard
  1177. 40:26input. Even though you're attached to
  1178. 40:28its console, it isn't able to read any
  1179. 40:30input from you. It doesn't have a
  1180. 40:31terminal to read inputs from. It runs in
  1181. 40:33a non-interactive mode. If you'd like to
  1182. 40:35provide your input, you must map the
  1183. 40:37standard input of your host to the
  1184. 40:39Docker container using the dash i
  1185. 40:41parameter.
  1186. 40:43The dash i parameter is for interactive
  1187. 40:45mode, and when I input my name, it
  1188. 40:47prints the expected output. But, there's
  1189. 40:50something still missing, the prompt.
  1190. 40:52When we ran the app at first, it asked
  1191. 40:54us for our name, but when Dockerized,
  1192. 40:56that prompt is missing, even though it
  1193. 40:58seems to have accepted my input. That's
  1194. 41:01because the application prompts on the
  1195. 41:03terminal, and we have not attached to
  1196. 41:05the container's terminal. For this, use
  1197. 41:07the dash t option as well. The dash t
  1198. 41:09stands for pseudo terminal. So, with the
  1199. 41:11combination of dash i and dash t, we're
  1200. 41:14now attached to the terminal as well as
  1201. 41:15in interactive mode on the container.
  1202. 41:18Now, you might be wondering, "Why would
  1203. 41:20I ever use dash i alone or dash t alone
  1204. 41:23if dash i t is the real combination?"
  1205. 41:26Well, they both have honest use cases.
  1206. 41:28They're just narrower. The dash i flag
  1207. 41:30alone is the right choice when I'm
  1208. 41:32piping data into the container. I want
  1209. 41:34standard input connected so the
  1210. 41:36container can read my data, but I don't
  1211. 41:38need a terminal because I'm not typing
  1212. 41:40anything. The classic example is piping
  1213. 41:43a SQL file into a Postgres container. If
  1214. 41:46I tried dash i t here, Docker would
  1215. 41:49actually refuse because pipes aren't
  1216. 41:51terminals and dash t insists on one. So,
  1217. 41:54for any kind of streaming pipeline, dash
  1218. 41:57i alone is exactly what you want. The
  1219. 42:00dash t flag alone is for when I want
  1220. 42:02colored output or progress bars, but I
  1221. 42:04don't need to type anything. Programs
  1222. 42:07check whether they're attached to a
  1223. 42:08terminal to decide whether to emit
  1224. 42:10colors and pretty formatting. With dash
  1225. 42:12t, the program thinks it's talking to a
  1226. 42:14real terminal and gives me the rich
  1227. 42:16output.
  1228. 42:17And without {dash} i,
  1229. 42:19I skip wiring up the keyboard I'm not
  1230. 42:21actually using.
  1231. 42:22In practice, I reach for {dash} it most
  1232. 42:24of the time.
  1233. 42:25{Dash} i alone when I'm piping data in.
  1234. 42:29Now let's look at port mapping or port
  1235. 42:31publishing
  1236. 42:32on containers.
  1237. 42:33Let's go back to the example where
  1238. 42:36we run a simple web application in a
  1239. 42:37Docker container on my Docker host.
  1240. 42:40Remember the underlying host where
  1241. 42:42Docker is installed is called the Docker
  1242. 42:44host or Docker engine. When we run the
  1243. 42:46containerized web application, it runs
  1244. 42:48and we can see that the server is
  1245. 42:51running. But how does a user actually
  1246. 42:53access my application? My application is
  1247. 42:55listening on port 5000, so I could
  1248. 42:57access it on port 5000. But what IP do I
  1249. 43:00use to reach it from a web browser?
  1250. 43:02There are two options. One is to use the
  1251. 43:03IP of the Docker container. Every Docker
  1252. 43:05container gets an IP assigned by default
  1253. 43:08like the one here.
  1254. 43:09But remember this is an internal IP and
  1255. 43:11is only accessible within the Docker
  1256. 43:13host.
  1257. 43:14So if you open a browser from within the
  1258. 43:16Docker host, you can go to that
  1259. 43:17container IP on port 5000. But since
  1260. 43:20this is an internal IP, users outside
  1261. 43:23the Docker host cannot reach it. For
  1262. 43:25that, we use the IP of the Docker host,
  1263. 43:27the
  1264. 43:28the one you see here. But for that to
  1265. 43:30work, you must have mapped a port inside
  1266. 43:32the Docker container to a free port on
  1267. 43:34the Docker host. For example, if I want
  1268. 43:36users to reach my application through
  1269. 43:37port 80 on my Docker host, I map port 80
  1270. 43:40of the host to port 5000 on the
  1271. 43:42container using the P parameter. And so,
  1272. 43:45the user can now reach my application by
  1273. 43:47going to that host IP on port 80. And
  1274. 43:50all traffic on port 80 of my Docker host
  1275. 43:53gets routed to port 5000 inside the
  1276. 43:55container. This way, you can run
  1277. 43:56multiple instances of your application
  1278. 43:59and map them to different ports on the
  1279. 44:01Docker host or instances of different
  1280. 44:03applications on different ports. For
  1281. 44:05example, you could run an instance of
  1282. 44:07MySQL listening
  1283. 44:08on its default port 3306 and another
  1284. 44:11instance of MySQL on port 8306. So, you
  1285. 44:14can run as many applications like this
  1286. 44:16and map them to as many ports as you
  1287. 44:18want. And of course, you cannot map to
  1288. 44:20the same port on the Docker host more
  1289. 44:22than once. We'll discuss more about port
  1290. 44:24mapping and networking of containers in
  1291. 44:26the network lesson later on.
  1292. 44:29Now, let's look at how data is persisted
  1293. 44:31in a Docker container. Let's say you
  1294. 44:33were to run a MySQL container. When
  1295. 44:35databases and tables are created, the
  1296. 44:37data files are stored in var/lib/mysql
  1297. 44:40inside the container. Remember, the
  1298. 44:42Docker container has its own isolated
  1299. 44:44file system and any changes to any files
  1300. 44:47happen within the container. Let's
  1301. 44:48assume you dump a lot of data into the
  1302. 44:51database. What happens if you were to
  1303. 44:53delete the MySQL container and remove
  1304. 44:55it? As soon as you do that, the
  1305. 44:57container along with all the data inside
  1306. 44:59it gets blown away, meaning all your
  1307. 45:01data is gone.
  1308. 45:03If you'd like to persist data, you'd
  1309. 45:05want to map a directory outside the
  1310. 45:07container on the Docker host to a
  1311. 45:10directory inside the container. In this
  1312. 45:12case, I create a directory called
  1313. 45:14opt/data dir and map that to
  1314. 45:17var/lib/mysql
  1315. 45:19inside the Docker container using the
  1316. 45:21dash v flag specifying the directory on
  1317. 45:23the Docker host followed by a colon and
  1318. 45:25the directory inside the container. This
  1319. 45:27way, when the Docker container runs, it
  1320. 45:29implicitly mounts the external directory
  1321. 45:30to a folder inside the container. All
  1322. 45:32your data will now be stored in the
  1323. 45:34external volume at
  1324. 45:36data dir and will remain even if you
  1325. 45:39delete the container. Now, a quick note
  1326. 45:41on the dash v form versus the dash dash
  1327. 45:44mount form.
  1328. 45:45Modern Docker has a more explicit syntax
  1329. 45:48called the dash dash mount form. The
  1330. 45:50same bind mount is rewritten using key
  1331. 45:52value pairs, type, source, and target
  1332. 45:54instead of a single colon separated
  1333. 45:56string. Both work. The dash v form is
  1334. 45:59not deprecated, but the dash dash mount
  1335. 46:02form makes the type of mount explicit,
  1336. 46:04bind, volume, or tempfs, which becomes
  1337. 46:07more useful as your setup gets more
  1338. 46:09complex.
  1339. 46:11The Docker ps command is good enough to
  1340. 46:13get basic details about containers like
  1341. 46:15their names and IDs, but if you'd like
  1342. 46:17to see additional details about a
  1343. 46:18specific container, use the Docker
  1344. 46:20inspect command and provide the
  1345. 46:22container name or ID. It returns all the
  1346. 46:25details of a container in JSON format,
  1347. 46:27state, mounts, configuration data,
  1348. 46:29network settings, and more. Remember to
  1349. 46:31use it when you need to find details on
  1350. 46:34a container. And finally, how do we see
  1351. 46:36the logs of a container we ran in the
  1352. 46:38background? Uh for example, um I ran my
  1353. 46:41simple web application using the {dash}d
  1354. 46:43parameter, and it ran the container in
  1355. 46:45detached mode. How do I view the logs,
  1356. 46:47which happen to be the contents written
  1357. 46:49to the standard out of that container?
  1358. 46:51Use the Docker logs command and specify
  1359. 46:53the container ID or name. An example
  1360. 46:55output might look like this. Well,
  1361. 46:57that's it for this lesson. Head over to
  1362. 46:59the challenges and practice working with
  1363. 47:01Docker commands.
  1364. 47:04>> [music]

About this transcript

This page contains the full transcript of Docker Explained for Absolute Beginners [2026] by KodeKloud, generated from the public captions YouTube serves with the video. The transcript has 8,858 words across 1,364 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.