Learn Docker From Scratch [2021] | Andrei Dumitrescu | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

16 Lessons (1h 36m)
    • 1. Welcome to Docker Essentials

      2:36
    • 2. What is Docker? Why use it?

      4:58
    • 3. Installing Docker

      8:10
    • 4. The Docker Client

      3:57
    • 5. Pulling Images and Running Containers

      11:13
    • 6. Lab: Running a Web Server in a Docker Container

      5:03
    • 7. Listing Images and Containers

      4:19
    • 8. Removing Images and Containers

      8:11
    • 9. Getting Shell Access to a Container

      6:23
    • 10. Executing Commands in a Running Container

      3:13
    • 11. Getting Information about the Running Containers

      6:31
    • 12. Committing Container Changes into a New Image

      6:25
    • 13. Tagging and Pushing Custom Images to Docker Hub

      4:47
    • 14. Image Structure and Layers

      4:27
    • 15. Creating Custom Images using Dockerfile

      10:52
    • 16. Persistent Data: Volumes

      5:02
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

73

Students

--

Projects

About This Class

Welcome to this class on Docker Essentials!

By the end of this class, you'll know how to run containerized applications with Docker.

This hands-on course goes straight to the point without any distraction and focuses solely on how to use Docker.

The Docker project started in 2013 and became the de-facto standard for executing programs in a portable sandbox environment aka container. It’s probably one of the reasons for the high rate of cloud adoption in the industry. Learning Docker now could be the best decision of your career! If you invest your time and effort in learning these skills TODAY  it will pay off greatly in the FUTURE. 

Since this is intermediate Linux, before enrolling in this class you have to already master the basics of the Linux commands. Some basic knowledge of Networking, in general, is also required. Once you have a grasp on Linux and Networking Basics, you can move on to Docker.

My advice is to first check my other classes on Linux Administration published here on SkillShare: they will help you build a strong foundation of Linux. 

The class projects will help you use the knowledge in a practical way and the skills you’ll learn will broaden your horizons and increase your value on the job market.

Major topics of this course:

  • Project Overview
  • What is Docker? Why use it?
  • Installing Docker
  • The Docker Client
  • Pulling Images and Running Containers
  • Lab: Running a Web Server in a Docker Container
  • Listing Images and Containers
  • Removing Images and Containers
  • Getting Shell Access to a Container
  • Executing Commands in a Running Container
  • Getting Information about the Running Containers
  • Committing Container Changes into a New Image
  • Tagging and Pushing Custom Images to Docker Hub
  • Image Structure and LayersCreating Custom Images using Dockerfil
  • Persistent Data: Volumes

and more! 

Meet Your Teacher

Teacher Profile Image

Andrei Dumitrescu

DevOps Engineer and Professional Trainer

Teacher

I've been a Network and Software Engineer for over 15 years, the typical profile of a DevOps Engineer.

I've cofounded Crystal Mind Academy, a Cisco Academy and professional training center in Romania,  that focuses on teaching cutting-edge technologies to students.

I have contributed to education in areas of programming, information security and operating systems. During the last 12 years more than 20,000 thousand students have participated in-person or online  training programs at Crystal Mind Academy. 

I have developed documentation, labs and case studies for many training programs such as Cisco CCNA, CCNA Security, CCNP, Linux Administration, Information Security, Python Programming, Network Automation with Python or Blockchain Programming (Ethereu... See full profile

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Welcome to Docker Essentials: Hello and welcome to this class on Docker essentials. My name is Andre Dmitry School and I'll be your instructor for this class, as well as lots of other classes here on askew share. In the list practical class, I will show you how to run containerized applications with Docker. The Docker project started in 2013 and became the de facto standard for executing programs in a fourth above sandbox environment, aka container. It's probably one of the reasons for the high rate of cloud adoption in the industry. It's high time for you to jump on board. Docker changed the IT infrastructure and everybody uses it. If you think of any cloud provider like Amazon or Google, or any of today's big corporations, probably they use Docker. Practical section will start with an overview of what is Docker, what are its components and what part of the Docker images and containers. Then we'll move on to install Docker on Linux and how to use the Docker CLI. I'll teach you how to pull images from the Docker Hub in how to run containers, you will know how to commit the changes to a Docker image and push it to the docker hub. I'll show you how to list images in containers. How to execute shall commence in a running container in how to stop on the movement. Next, we'll move ahead to contain our monitoring Docker image structure. How to create custom images using docker file, or how to use persistent data using volumes. And finally, we'll discuss networking in Docker. At the end of the class, you will know how to run containerized applications in Docker. If you invest your time and effort in learning these skills today, it will pay off greatly in the future. Sees this is intermediate Linux. Before enrolling in this class, you have dominate the mass start at the basics of the Linux commands. Once you have aggressive on Linux and networking basics, you can move on to Docker. My advice is to first check my other classes. Only knocks administration, published here on skill share. They will help you build a strong foundation of Linux. The class projects will help you use the knowledge in a practical way and the skills you learn will broaden your horizons and increase your value on the Java market. See you in the first lesson. 2. What is Docker? Why use it?: Hi and welcome back. Lexie, what Docker is NYU's it. Docker is a platform used by developers and sysadmins to develop, deploy Enron containerized applications. The use of Linux containers to deploy applications is called containerization. What is a containerized application or simply a container? A container is a running process that encapsulates everything I'm application needs to run. And only those things. This way, Docker makes it really easy to install software without worrying about the setup or dependencies. Docker containers allow applications to be shuttled easily between environments. For example, you can develop an application using any technology you want and then take it from your laptop and move it to any other Linux distribution, Amazon Web Services, Google Cloud, or the Microsoft Azure Container environment, all without the need of a making any adjustments to the code. Legacy, how a container compares to a VM, both being infect isolated environments. Take a look at these two images. The image on the left represents our traditional virtual machine architecture. At the bottom in green, there's the physical machine and a hypervisor is installed on the physical machine. This layer manages the communication between the guest VM operating system and the physical host. The applications deployed on the guest operating system. She at the VM resources. On top of this, host, VMs required a full OS in the lap of unnecessary libraries to be installed in Iran in vitro requires a lot of space and resources. So VMs are slow to put and waste lacks of resources. When the deployed applications on the host VMs do not see much traffic. The full OS of the VM is running. So traditional VMs are not efficient at all. You don't need to run a full OS just for a tiny app. Containers. On the other hand, ron EPA, the application layer, and the share of the operating system and kernel with the other containers. They don't need the full guest OS is the VM subdue. They only isolates the applications. Let me give a practical example. You are required to set up a full-stack using different technologies, a web server using Node JS, a MongoDB database, an automation framework such as instable or salt. In the many other technologies. This can bring your lacks a vicious because you have to ensure they are compatible not only with the version of the operating system, but with each other as well. Maybe a component needs a specific version of what libraries such as Python two and another component and x, another version such as Python three. Any experienced developer can tell you that, that this could be a nightmare. This is known as the matrix of hell. The problem can be solved easily and elegantly by running each application in its own portable and isolated container. And when you want to deploy or to install the application on another system, you have no worries about what OS is installed. You just need the darker on the system. Now that you know what the container is, Let's see what is a Docker image? An image is a standalone, isolated, lightweight, and executable package that contains all the required components, code, runtime, system, tools, libraries, settings, and so on. All of X unnecessary to run the application. So an image is an application you want to run in the container is the runtime instance of the image. From the same image, you can launch more containers. The isolation insecurity allowed to run many containers simultaneously on a given host. Images for many applications can be found on Hub data Docker.com. Let's search for some well-known applications, such as MongoDB, MySQL, or in genetics. So I'm searching for Mongo. Indeed found 40 thousand images and MySQL. And there are 24 thousand images. And of course thousands of images for engine engineers as well. We'll take a short break and in the next lecture, we'll install Docker. 3. Installing Docker: Let's install Docker on Ubunto. For awhile. Dakar didn't work natively on Windows or Mac, but there any inner Linux VM in the background, because Docker was made for a Linux. If we install it on Linux, there's no VM or emulation and equal around directly on your Linux OS. There are two versions, darker sea or Community Edition, which is free, and the darker II or Enterprise Edition, which is a paid version and disinfect Docker CE, but with certifications on some systems in a support given by Docker. In this section, we'll use the community edition. There's also an H or beta in the stable release. Back in mid 2018, Docker announced that the new CE, stable of Ulysses would be every six months and the release name follows the notation E dot month. So for example, 2010 means here 220 month. Then since mid 2020, releases are still following the year, about a month pattern, but there's no longer a pre-defined set schedule. Legs get started. I'll install Docker on a Linux server, the veterans in the Digital Ocean cloud. You can create the testing account on Digital Ocean in started droplet with a virtual private Linux server or install it in virtual box or VMware is a normal Linux VM. On docs dot docker.com, you'll find instructions for each distribution. Will install the Docker engine, which is a client server application with three major components. Or server or a daemon process called Docker D, a command line interface called the Docker VCs referenced to as the Docker command and the rest API that specifies interfaces used to communicate with the Docker Daemon. Forest will uninstall any old versions. Older versions of Docker or called Docker, Docker dot io, docker engine if with the agonist told on installed them. So pseudo APT remove Docker, Docker, container d, and the run see 0x, okay, if APT reports that none of these packages are installed. First, I'm aiding Docker's official GPG signing key. I'm copying and pasting this comment. I'll follow the official instructions. So first time aiding the official Docker repository to stay up to date, I won't install it from the official Ubuntu repo. So I'm copying and pasting this command in the terminal. And I'm running sudo APT update. I'm installing it from the Docker repository, not from the Ubuntu repository. So APT cache policy darker minus c. And I'm running sudo APT install Docker minus C, Docker minus c minus CLI and container d dot IO. In time hitting Enter, it's downloading and installing Docker. We are waiting a few seconds. Let's check status, pseudo system CTL status. Docker. Docker is active and running. If you want to run the Docker command without being rude or using pseudo head, the user veterans, the comment to the docker group that was already created. So I'm adding the current user to the docker group. So pseudo user mod r minus a capital G Docker. And the user, in my case, the username is student. I'm logging out. And then even for the change to take effect. And I'm running docker minus minus version to check if the Docker Client can talk to the Docker Daemon or server. They can talk. Okay. Docker was installed and running. And I'll show you something that could be useful. Sometimes I'm opening labs that play with Docker.com. Maybe you don't have local admin. Maybe our machine doesn't have enough resources, or you just want to test something quickly without starting a Linux VM. Well, the best free option here is to use PWD or play with Docker that como E2 around one or more docker instances inside your browser and give you a terminal to use it with. So I'm clicking on login and I'm selecting Docker. And I'm clicking on Start. You can actually create multiple machines on it and even use the URL to share the session with others in a sort of collaboration experience, I highly recommend you to check it out. Most of the lectures in this course can be used with PWD. Note that x limited to four hours, at which time it will delete your servers. So I made a new instance. It's creating the instance Xerox's Docker in the sandbox environment. Let's run some Cummings Docker, container Huron minus D minus I, D MG. Next, I'm targeting engine X, the well-known web server in a Docker container. It's pulling the image from Docker Hub and then launching the container in dimer running docker container, BS, two Elise dollar running containers. And we see that the engine X container is running. Okay. That's all for the moment. Thank you. 4. The Docker Client: The Docker Client, also known as the Docker image and container command-line interface, is a client that interacts with the Docker Daemon. To see Docker version in the client can communicate with the server or on Docker minus-minus version or darker version. To see much more information. You can also run docker info to see systemwide information including the number of containers in damages. We have 0 containers and 0 images to seeks help. Either are on Docker with no parameters or Iran Docker help. The new way of executing the Docker comment is Docker Management Command, SOP command, and options. Each Docker management comment has more subcu makes available. For example, these are all management Cummings indicates see each of their help either by running docker, endo management comment with no parameters, or Docker though Management Command and help for exemple Docker container. Where container is a management comment and displaying the help of Docker container or Docker container help. It's the same. For exemple Docker container Ls. We released the running containers and Docker image. Ls will at least the available images to test the entire Docker installation, including the communication with the docker hub around Docker container on end, hello world. E2 will try to run the hello world container by searching Forest for the image locally. And if it doesn't find it locally, eat some cheese and downloads it from the Docker Hub. So it was unable to find the image locally and downloaded or pulled it from the Docker Hub. Hindus got to this message, says that the installation is working correctly. It's also showing the steps Dakar took to run the container. The image was saved locally. So the next time I start a container from the image, it will not pull it again from the Docker Hub. I'm running the command again. M. It's not pulling the image again from Docker Hub. Note that there's also an older way of running the Docker comment without the management comment is an argument. For example, instead of Docker container run, you'll see some examples. Docker run and the container name, like docker run, hello, minus world. This is the old way of running the Docker comment. In this course, we'll use the new form of the Docker command. So instead of Docker on into the mix, I'll use Docker container around in the image of x. All you've learned, what is the basic usage of the Dakar CLI in the steps it takes to run a container. 5. Pulling Images and Running Containers: It's time to see how to pull images from Docker Hub and Ron containers. Docker happiness or service provided by Docker for finding and sharing container images. It's the world's largest repository of container images with tens of thousands of containerized applications available is Docker images. You can search for an image in the browser on Docker hub or indirect terminal using the docker comment, for example, I am searching for MySQL, and it found almost 25 thousand images. The Docker images used the following naming convention. The repository registry, hostname or organization of forward slash in the image name. Let's take a look at police on the name of the registry. Hostname is MySQL. In the name of the image is MySQL server. It's an optimized MySQL Server Docker image created, maintained and supported by the Oracle MySQL team. If you visit the image page, you'll see a short description of the image together with some examples of how to use it. There are also images called official images, that are created by a Docker dedicated team that is responsible for viewing and publishing the contents of the image. These images don't have a user or a repository csa. They reside at the root level of the Docker Hub. For example, these forests to images are official. My advice is to use them official image or one under the authority of the official team that creates the software to be sure that it's a quality one. To search for an image using the docker CLI around docker search. And the image name like say Debian or mongo. Also, they can look at the number of stars an image has when choosing one. When working with Docker images, you'll come across tax. So what exactly are these image tags? In simple words, image tags convey useful information about the specifics you mix version. But can be a number or a name as well. Let's go to Docker Hub and take a look at the random image. I'm searching for her eddies, which is an in-memory data store used as a database. In Dima visiting the image page. On the image page, you will find the section where it says supported X. You can download and use a specific version of the software by using the tag after the image name separated by a colon. For example, I want to download and use an older version for compatibility, like say five dot 0 dot temp. And I'm running Docker image, pull this colon, five dot, dot, dot ten, and it's downloading the reddest image with the tag five dot 0 dot ten. To list all the locally available images. Run docker images or darker image ls. And you see there the radius image I've just pulled from the Docker Hub. An image can have more texts and they all point to the exact same mimics. So I've pulled the image with the tag five dot 0 dot m. If I pull the ready CMYK using these tech five minus Buster, the image will not be saved twice because it's just the same image with different texts. Sorry, I'm running Docker image pool, read this colon five minus Buster. And then docker images. We see that both ready see images point to the same image ID. However, the same size sees how they act the same image. We also notice that an image doesn't have a name x identified only by a repository or user. One or more attacks in the single image ID. The darker images ID is a digest which contains the sha 256 hash of the image. And if we don't specify the tag when using an image, it will default to the latest. So running docker, pull away this this command is the same as docker, pull or air. This colon latest. So this one is the same as the Sun. It's the same image. Note that it's not mandatory to point to the latest version. It's just the default name and in general is the latest version of the stable software. By the way, you can create a new images from the existing ones and give them a tag, or you can retake the existing ones. We'll talk about that later in the course. Purana container from an image executes a Docker container. Or on the name of the mixin where this kinda container started. I'm exiting pressing Control C. If the image is not available locally, it will try to download it from the Docker Hub into then rhonda container. For example, I'm running docker container around minus capital P HTTPD. Httpd is the Apache web server that doesn't exist locally. So it's downloading it from the Docker Hub and then running the image. It has started in the foreground and the locks are printed to the console. To test that extra really working. I'll open a new browser tab and connect to the docker host machine IP address. So let's see what the API, the gaze of the docker host I splitting the terminal horizontally in time, connecting in this new terminal to the VPS virtual private server that runs in the Digital Ocean cloud using SSH. I've already created an alias to connect easier and faster. So VPS m by P. Okay, this is the public IP address of the docker host. I'm copying it to the clipboard, and I'm pasting it in the browser. Okay, the site can be reached because it didn't expose port 80. It has exposed a random port to the outside. I'm running docker container, ls to see the running container and the exposed parts. So this is the part, I'm copying it to the clipboard as well. And the base thing it here. So colon and the port number and exhorting Apache v6 running in the container has served each default page. I'm stopping it. Pressing Control MAC. Note that when I executed Docker container run behind the scenes, Docker created a container in started. So in fact, there are two different steps involved. Lakes around the cummings to see each step. So docker, container create minus b, a lowercase b. This time I'm exposing port 80, so AD colon 80. We'll talk more about these later in the course. And the name of the meter. So HTTPD, the container was created Docker container ls minus a will at least to the container. The Sun. Kim, I'm starting the container. So docker, container start and the container ID in the container started. The container is up in Lima refreshing the page, but using the default port, which is 80, handicaps working as well. So, you know, not shell, Docker container around means Docker container create plus Docker container started it at the end of this lecture, I will show you how to get a shell inside the container. Of course E4 Shelley's available. I'm running docker container or on minus I D send OS. I'm starting a container called sinth o is in getting a shell in the container. It's downloading the image and then starting the container. I'm in the centralist container. This is CentOS campaigner. I'm exiting the Exxon about pulling images and running containers. In the next lecture, we'll see how to run a web server in a Docker container. 6. Lab: Running a Web Server in a Docker Container: In this lab, I will show you how to run a web server in a Docker container. I'm gonna use NG next, which I think is the most used open source web server, it for the moment. So I'm running docker container around minus d minus p 8080 colon 80 minus, minus name, my site and genetics. Before hitting Enter, I want to explain to you each of the options minus d means detect and will make the process start. In the background is a demon. If you don't specify this option, he could run in the foreground, in the logs will be printed out in the console. Minus B 88 d colon 80 will expose the containers port 80 to Docker host port 8080. So the engine X container will allow listen on port 80. But the users from the land or the internet will connect to the port 8080 into the IP address of the docker host. They will not connect to port 80 on which engine X Lisa's. This way, you can run multiple containers that all listen on port 80 and port 82 different parks on the host. If there's only one container that listens on port 80, you can publish port 80 of the container to port 80 of the host. And if you use a capital P instead, a lowercase b, E2 to publish all exposed ports to random ports. Minus-minus name. My site is the name given to this container. If you don't specify a name, it will choose a random one from a pre-defined list of names. Or this is applicable to all containers. And next is the name of the image I'm hitting Enter. The comment will search for the image locally. And if it doesn't find, it, will search for heat and then download the image from Docker Hub to list all running containers. I'm running docker container, ls. Henry C of that to the container is running. In fact, there are two containers that ironic, engine X, I've just started in the container, started in the previous lecture. The Apache web server from the HTTPD image, I'm connecting to the web server. Lexi x ip address, again, the Swan. And in a new tab, I'm pasting the IP address colon and the port 8080. This is the exposed part, MD, MD next has given a default page, which means six working well. By publishing container sparks to different ports on the host. You can run more containers that listen on the same port. For example, I'm starting to other containers on the same host. The first will be another instance of MD. Next, the second will be the Apache two weeks. He's another well known open source web server. I'm publishing port 80 on the container to port 8081 on the host. Enlil, give it another name. Each name must be unique. Leg say my site on. This is the second campaigner. In the third container, I'm publishing port 8080 to two port ID. The name is my site to, in the name of the image is HTTPD. I'm running docker container ls. And we see a vet. All containers are up and running. Now, back to the browser, I'll access the server using port 8081. This is the second campaigner in dive received the standard web page from the second engine X container into access the Apache web server. I'll connect to the same IP address and port 8082. This is the standard Dart web page of Apache or 80. This is the container from the previous lecture, lease on. Okay, vix. All. In this lab, you've seen how to run a web server in a Docker container. 7. Listing Images and Containers: In this lecture, we will see how to list the Docker images in running containers to see all the locally downloaded images around either Docker images or Docker image ls. The later comment is the newer form of the Docker command. If for some reason you don't see any image, just pull one from Docker Hub. For example, I'm pulling the CentOS image. I already heavy bob, I'll pull it one more time. So docker, pull synth OS colon, latest. Latest is the default tag anyway. And it says that the image is up to the IPO, didn't do. I think now that you know how to display the available images, it's time to move ahead and see how to display the running containers. Just to be sure that there's at least one container, I will start the CentOS V1 I've just pulled from Docker Hub. If I started the container by running docker container around sent OS, like these, the container will be started, but having nothing to do, it will exit silently. But container is not running. Heat has exited. So I have to specify a comment to run in the container in by 1r comment that takes some time, like say pink. So I am bringing the loopback interface. Docker container, Khurana CentOS being in the IP address of the loopback interface. Remember, if I don't tell the container Toronto comment, it won't have anything to do him. So E2 will shut down immediately. In another terminal. I'm connecting pulled the Docker server using SSH. If you run Docker in a local Linux VM, just open up. Another thing coming up. We'll see all running containers are on either darker BS or Docker container Ls. So there are five running containers. Docker ps is a shorthand that stinks for Docker process status wireless to Docker container ls is a shorthand for the Docker container list. There's no difference in how they work, but the Docker container, Ls is the New York comment. So should probably prefer it to list both running in exited the containers. So all containers that have ever been started around either docker ps minus a OK, these command or Docker container ls minus a. These are all the containers ever started. Since we started the section. You can even filter the containers by their status. For example, to see only exited containers around Docker container ls minus a minus f status equals exited. In the far interested only in their ID. Like when you want to restart to the containers or remove them, then it, the minus q option. It has printed out only the containers IDs. That makes all. Thank you. You now know how to list images and containers. See you in the next lecture. 8. Removing Images and Containers: Welcome back. It's time to show you how to remove images in containers. Legs, what are the available images? I'm starting the engine X Web Server, Docker container. So docker container around minus d minus capital P minus, minus name, my website, MG. Next, I'm checking that IQ surrounding by typing Docker container ls. Here the container is running. Now, I want to remove both the meat in the container imbalanced. Start with the container. To remove a container, you have to stop it Forest in the movie. So I'm running Docker containers stop in the container ID to stop it. Docker, container stop and the container ID. So three to six a x and map necessary to write to the entire container ID. You can write only the first few letters of the container ID, as long as it uniquely identifies the container. The container who was stopped in by Kennedy movie it by running docker container. And the container ID. I have removed the container. You can also remove a running container by adding the minus F option. If comes from force. I'm starting the engine next container. Again. The container is running and I'm trying to remove it without stopping it first, Lexi excite the releases.com tamer in dimer running docker, container. And the container ID, in fact, only the first few letters. And it says that I came up remove a running container, I have to stop it first or force remove it. And I'm aiding the minus F option. Kinda container was removed successfully. Lex least all containers both stopped in running. Docker container, ls minus a. Then R lacks of containers. All the containers sees, we have started this section of the course to filter the campaigners on their status. Use the minus f status option like this. For example, I want to see only campaigners they have with the exit status. So minus AF status equals exited. Or all the containers in the created status. Let us none. But this state results when you run a container with an invalid comment. If I add the minus q option, drag this minus q comes from quiet. It will print out only the container ID. Now I can remove all stopped or exited containers by running docker container RAM in a commend substitution that gives us the IDs of the stopped containers, libraries. So docker container, RM and the command substitution. So dollar and least commend between parentheses. The comment will return a list with all exited containers, and there'll be moved by the first comment by Docker container argument. In all stopped containers or removed. I have listed Hall containers both exited and running, and there are only running containers. Let's move on and see how to remove an image. To remove an image around Docker RMI or Docker image RAM in a list of images to remove. I'm listing all available images again. In dimer running Docker image RM simplys. And the image was removed. If I tried to remove an image that is being used by a container which could be stopped or on ink. I'll get an error. Docker container ls to see all running containers in vile tried to remove the engine X e mix em. It says that it cannot remove it because it's being used by container. So to remove the image, I have to remove the container first. I'm stopping the container by running Docker containers top in the container ID. So docker container stop and the VR2 campaigners, VIP are using the NG next image. So I'm writing for their IDs 167068. So there are stopped. It's not necessary to write to the entire container ID. The containers still exist, but Parramatta running, There's no engine next containers that are running, but they still exist. The DAG exited. Even though the container is not running, I cannot still be moved. The image, I've got to the same error. So I'm removing the containers. Instead of stop. I'm writing rM0 in the container or removed. Now I can remove the image. Then the image was removed. Note that you can also remove an image that these referenced by running or a stopped container by adding the minus f flag to the Docker image RM command with the sun into the end. Let's talk about the dangling images. Docker images consist of multiple layers. Dangling images are layers VIP have no relationship with any tagged images. They no longer serve a purpose in consume disk space. To delete them, you can run docker system run. In addition to removing dangling images. It will remove all stopped containers, all networks not used by at least one container, and all dangling bill cache. And if you add the minus a flag, it will remove all unused images, not just dangling ones. Alright, next all you've learned how to remove Docker images and containers. 9. Getting Shell Access to a Container: In the last lectures, we have seen how to pull images from Docker Hub, how drawn containers from those the mixes in how to list available images in running containers. Just as a short recap, to start the container, you're on Docker container Iran in the name of the mix. You can also give a name to the container. Minus-minus name equals contain around sent OS, exposing the image and running the container. Index done. You've probably supposed that to the container is running, but Vicks and not true. If you execute Docker container ls, to see the running containers, you won't find EAP In the running container, at least. The CentOS container is not running. These two containers. Httpd artist from the previous lecture. The new container is not running because by default, when you start a container, a default command is executed and when that comment execs, the container will exit as well. In the case of CentOS, the bash shell is the default command that gets executed. Just the vet, it exits immediately, enter the container stops. If I add the minus option, I will find the synth OS container in the exited containers least. Look this one. You can override the default command, in this case, bash, by specifying a comment with arguments after the image name. When starting the container. I'm executing the command that Starks the container. Again. I'm giving it another name, container talk. And I'm adding a commit, for example, cat slash EDC password. This time it will execute the cat command and when the comment exits, the container will stop Israel. This is the output of the command and the container has exited. Sometimes you want to get access to the container to install other programs or to change settings. Let's see how to get Sherlock says to the container, I'm starting the synth OS container again. This time editing the minus i into minus D options. I'm going moving document. I'm giving it another name, container, a free end. I made it minus i d note of it. It is not allowed to have more containers with the same name. Minus, i mean it's interactive and T means TTY. E2 will allocate a pseudo terminal. Or practically it means that other container Starks and through taxes is given in a shell. I'm hitting Enter. I mean, the CentOS container is what I can install other programs or to make changes to the container I'm installing. For example, n map, which is the net torque scanner. So I'm running yum install and map, heats installing and map. If I exit, bash will stop in the container is well, I'm typing exit. If I want to see the list of containers, you'll notice that the container has exited status. So I am executing Docker container ls minus a m. My last container has exited 12 seconds ago. I'm starting a new container using the same command. I'm just giving it another name, container for end. I mean the container to exit from a running container without stopping it. Press Control. B and Q. Iit has exited, but leaving the container running in the background. If I list all containers, again, I'll see that the last one is still running. Heats up 439 seconds in. They can attach to it again by getting a shell or I can stop it. Stop the container. I run docker container, stop in the container ID. And to get the shell in the running container higher on the bash shell in the container using the exec option like this, Docker container, exec minus I, d, the ID or the name of the container. So for line six, CD and document bash, I mean the container. I'm exiting the container again without stopping it by pressing control P and Q. And the container is still running in the background. It's only the up for two minutes. And finally, I'm stopping the container by running docker container stop and each ID or its name. Thanks. U6, name container for the container was stopped. 10. Executing Commands in a Running Container: Getting Sherlock says top container and running in the container is very important. So I will show you again very quickly how to do it. When you start the container. Based on the containers type, a default comment starts for a Linux distribution. Bash is the default comment. I'm starting Debian in a container. So docker container Huron, Debian. It's pulling the image and the running container index done. The bash shell was started and then exit it immediately in the container, exited as well. I'm running Docker container again, this time interactively to get Sherlock says, hi, I'm adding minus IT. I mean the container in my Kindle, anything I like, I'm exiting in the container execs as well. The container is not running. It's exited. I can start it back again by running docker container start. End XID, mine 070. Remember that each Commendatore to write the entire container ID. The container is running in time connecting to the same container. And getting Shylock says Docker container exec minus I d, the container ID. And document the bash. I mean the container to exit to the container without stopping it, I'm placing P and Q. The container is still running in. They can execute any commands you need without getting shall axis, docker, container, exec, and shadow. Alright? Please exercise until you master them because they're really important. 11. Getting Information about the Running Containers: In this lecture, we'll discuss how to get useful information about the running containers. There are many containers both stopped into running from the previous lectures. And to keep it simple, I remove them all. So docker container RM minus F, I'm forcing the removal and a command substitution. A dollar, a pair of parentheses in the Docker command that will at least all the containers IDs. So docker container ls minus a and q. Q from quiet, it will print out only the IDs of the containers. Now, there is no container in time starting an NG next Web Server, Docker container, Docker container around minus d minus B 88, the colon 80 minus, minus name equals my site MD. Next. To see you all running containers. I'm executing Docker container ls. The engine X container is running. Let's take a look at the output where each line represents a container. For the moment, there's only one container running. The first field is the container ID, which is unique. You use it when you want to interact with the container, for example, stopping or you rhyming or removing it. The second field is the Docker image from which the container started. Then comes the comment that was executed. When was it created? 0x status, the API and the exposed port on which deletions in the last field is a name that is specified with the minus-minus name option when we started the container or a randomly chosen from a predefined list if no name is given. You'll see important information on the screen. If you want to see only the API and the port, urine Docker, container port in the name whore, the idea of the container. My site links connect to the web server from the internet. And this is the IP address of the docker host. I'm copying it to the clipboard and pasting it in the browser. In the port these 8080 to see the logs of the container. In this case of the web server or on Docker, container logs. And the name or the idea of the container, my site. These are the locks to see the logs updated in real time at the minus F option. This is similar to the tail minus f comment. I am a refreshing the page. And I see that there are new logline was displayed. Okay, I'm exiting the logs by pressing control C to see all the processes veteran in the container around Docker Container top end the name or the idea of the container. So there are two processes, a whip around and kinda container. All of these processes are running as seen on the docker host as well. They are not heed them into a container like him, a VM. So you fire on bs minus EF. I'll see the same processes I made being by progress in genetics. So these are the processes that are running in the container. You'll see it's the same process ID to display real-time information about all running containers around Docker container stacks. And there's only one container. If you toward more and want to see real time information only about the container and the container name or ID to document. Into C lacks of information about the container or on Docker container inspect in the container name or ID. There's a lot of information indeed, know Kim filter specific information using grep. For example, let's find out what is the private IP address of the container. So 5p minus i, I'm searching. Eni says it div, IP address. And this is the IP address of the container. Each container has by default own private IP address. We see the container IP and we can even pink or connect to eat. If there was an SSH server, it was running. Note Romania third party tools that can be used to monitor and collect metrics about Docker containers. 12. Committing Container Changes into a New Image: Up until now, you've learned the lax of useful things about running containerized applications with Docker. How to pull images from Docker Hub, how to on containers and monitor them or how to remove images and containers. Now, I will show you how to modify a container in a state of the changes into a new Docker image. If you start a container from an image, make some changes in the stock per second container from the same image. The changes will not be available to the second container. In fact, the changes are not saved in the mix. So I'm starting CentOS interactively in getting Shylock says tweet Docker container R1 minus Id, minus, minus name equals container on synthesis. I mean the container in Dial make some changes. I'm creating a new file installation route. So touch sledge wrote XYZ 2.txt. In the I'll also install n map, which is a powerful network scalar. So Yum a stall and map. Each downloading and installing and map. I'm also scanning a web server and map minus BAT. I'm scanning port 80, scan me dot.org. And the port is open. I'm exiting the container, which means stopping it. This is our container. The container is not running anymore. Iep exists but has the exited status. I'm starting a new container from the same image. So in fact, I'm running the same command that starts the container again. Just have it, I modify the name E and at least second container, the changes made in the first one are not available. The file we've created does not exist. It's not there. And N, The map is not installed. I'm exiting the container by typing exit in time starting the first one. So docker container, start and ID or name. Container and the container was started up. And I'm getting shellac says tweet. So docker container exec minus id, the name of the container, container one. And bash document I want to execute in the compiler. Now, all the changes we've done in the first place are available. The file is there and the map is installed. Let's move on and see how to commit the changes into a new Docker image. The first step is to start the container, make the changes and exit the container where the changes were made. So I'm typing exit Lexi XID because we'll need it. This is the container. The second step is to create a new image. I'm running docker commit minus m. And the message, what did you do to the image? Let's say n my app installed minus a in the author. The container ID, the username, or the repository. Remember that only Docker official images do not have a repository. Zai Di De Andre licks my username on Docker hub slash and the name of the new image, my underlying Santos. You can also add a tag. And if you don't do it, easy-to-use, the latest by default. In the new image was created. If you want to push the image to Docker Hub, the name of the local repository, DD Andre must make sure the username on Docker hub, Lexi, all available images. Docker image ls. This is the new image in they can start containers for Amit. Docker container around minus the the Andre slash my centralize. The container was started in by Linda container. And we notice that the both the file exists and the map is installed. We see all the changes we've done. 13. Tagging and Pushing Custom Images to Docker Hub: Let's see how to tag and push custom images to Docker Hub. I'm running Docker image ls to see all available images and receive that an image is identified. The biorepository, which is an organization or a username, one or more text, and a unique ID. That tag is a label that points to the image ID. All Docker images heavy repository except the official wise, which reside at the root of Docker Hub. For example, this is an official image and doesn't have a repository. All other images have repository. And if we take any image, we see that it can have one or more text. In this example, all of these three pegs refer to the same image. You can create a new images from the existing ones and give them a tag, or we can retake the existing ones. Let's add a new tech to some existing images. I'm adding a new tag called custom to the NG next image. So Docker image tag, the existing image and genetics. And then your tech, the repository, the Andre slash MG Next, colon, custom. Latest is the name of the default tag. If you don't specify any, note that that it's not mandatory to point to the latest version, x adjusts the default name and in general is the latest version of the stable software. In this case, the DeAndre is the repository and the username of the docker hub account. I'm adding a second tag, one dot 0 to the custom CentOS image to this one. So Docker image back the repository, the name of the image, my CentOS colon latest, This is the default. And then you take, so the andre, MY sent OS colon one dot 0. I have added a new tag to the same image. Note that the images are mapped, saved twice x, just the same image with two different texts. See you that they have the same ID. You can push your upload an image to Docker Hub by creating an account. Logging in and running docker push. I already have an account in dial push, the custom CentOS image. So darker login. The user name did the Andre wp password. The login succeeded. And by running Docker image, push Docker image bush. In the name of the mixin. My OS column, playtest. And I'm heating Ember. And it's pushing the image to Docker Hub. If you get the denied access there are make sure that you've successfully locked in and the username on Docker hub is the same as the local repository. In this case, the DeAndre. I'm going online and refreshing the page. And the image is there. This is the image. Now everyone can pull and use it. Note that on Docker hub, they are public and private repositories. And when pushing to a private repository, the image will not be freely available to other users. 14. Image Structure and Layers: Let's dive deeper into Docker images. Let's take a look at the VC mix in the official Docker documentation. An image consists of multiple layers. They are read-only and each of them has a unique ID. Larry saved on disk only once. It can be used by more than one image. For example, a layer from the Ubuntu image can be used by both engine X in the pixie images. This way, both disc space in time will be saved when pulling the image. Each layer is only a set of differences from the layer before it. The layers are stacked on top of each other. When you run a container from an image, a new writer bilayer is added on top of the image layers. These writable layer is often called the container layer and allows you to make changes to the container. Since the lower layers in V mics are gonna read only all changes made to the running container, such as writing new files, modifying existing files in deleting files are writing to this thin writable contain MAC layer. Note that the files won't be persistent after the container is deleted. And the both read and write speeds are lower than the native file system performance. And when we remove our container, we remove infact. This theme right, double layer, the other layers of the meat. And you may not attached. To write the data in the right double layer of the container. Docker uses something called storage drivers. There are more such storage drivers, for example, auxiliary file system overlay and overlay to the later one. Overlay to is the default in the recommended one. See the layers of the image, among many other things, are on Docker image inspect. So Docker image inspect MG. Next. We are seeing Glaxo information such as the image ID or shot 256. All expects the storage driver type, which is overlaid to end the id of x layers. So there are five layers on disk. They are located in var lib docker, overlaid to okay, I have to run the command desert. These are the layers of the images that are saved locally. Let's move on and talk about the container size. I'm starting to new containers from the NG next image, Docker container, boron minus d minus capital P MDX. And the second container. Containers are running. To display the size of the running containers. Use Docker container BS, minuses, and received two different values related to the size. Size is the amount of data on disk that is used for the write-up while layer of each container in the virtual size is the amount of data used for the only image layers plus the containers, right? Double layer size. Multiple containers may share some or all read-only image data into containers started from the same image, like in this example, share 100% of the read-only data. While two containers with different images that have layers in common, shared only those common layers. Therefore, you cannot just add the virtual sizes. That makes no sense. 15. Creating Custom Images using Dockerfile: Hi and welcome back. Now that you know so much about Docker images and containers, it's time to talk about Docker file. A Docker file is a text file that contains all of the instructions needed to create an image. It's like a recipe for creating Docker images. All the images used so far were created from Docker files. Lex, go to Docker Hub. I'm searching for engine X and selecting the official image restaurant. Of course, you can do the same for any other image. I'm moving down to the tags section in by clicking on the latest tech vaccine factor link. That will take me to the images Dockerfile. So this is the Docker file of the official engine. Next image by convention, it's name is Docker file, written in one word with a capital D. Let's take a closer look at its contents. Note that this is not a Bash shell script. It's something that is particular to Docker. The Docker file consists of comics and the instructions with arguments. In this example, from he's an instruction. And the Debian colon Buster sleep is an argument. The instructions are not case sensitive. However, the convention for them is to use uppercase so that we can distinguish them from arguments more easily. When building the image Docker will around the instructions in the Docker file in order, any Docker file must begin with a from instruction. And this is very important. The Fromm instruction specifies the parent image from which you are building. This is normally a Linux distribution in the very common one is helping Linux because it is a small, simple and secure. And if you truly want to start with an empty container US from scratch. Then we see the label instruction, which sex domain tamer, and the ENV instruction, which comes from environment and is used to define an environment variable. In this example, engine X version is the variable and the 1.The 19 S6 is x-value eats like a key value pair. Then comes a very important instruction which is run. E2. Lauren shortcomings to install a set-up, the application that you learn in the container. The R1 instruction will execute any commands in a new layer on top of the current image. And we'll commit the results of x, y. Even though there are multiple comments, they are executed in fact, on a single line. You can always use a backslash to continue a single RUN instruction onto the next line. The double ampersand is used to chain all the comments so that they fit in a single layer. Double ampersand means logical end. So a commending the chain will be run only if the previous one returned successfully. Remember that each run instruction creates a new image layer. You'll see this way of running comings in all Docker fries. Another instruction is exposed. It will inform Docker container we listen on the specified port or ports. At runtime. You can specify whether the part that listens on TCP or UDP in the default is TCP. If the protocol is not specified, like in this case, it won't open the port automatically to the outside world, but it will open it only in the container. You have to use minus p option to publish it. And finally, there's the cmd instruction, which is the last one in the Docker file in provides a comment that will be run every time you launch a new container from this image, or every time you restart a stopped container, there can be only one seemed the instruction in a Docker file. Okay, vexed The Basics of Dockerfile. Now what should we do with such a file? Let's copy it locally to the docker host. I'm selecting all the contents, copying it to the clipboard, going to Docker host, and creating a new file called Dockerfile. And I'm pasting the context. I'm saving and quitting the file. Great. In the Docker file that R3 copy instructions that copy three scripts that are needed to initialize the web server in a specific way. Since we want a custom image, I'll remove those copying structures. Now, I can build the engine next image from the Docker file. But to make things more interesting, I lead my own instruction to the Dockerfile v6, why you normally use Docker files to customize or tweak official images. So I'm changing the index.html file that will be served by default to the clients. So in the Docker file before exposing dub part I mating 4K, dear slash USSR, share MG Next HTML. I'm changing the current working directory to the document root of the web server where the website resides. I could also use the run docker file instruction in the city comment bottle. This is preferable in Docker files. Nb. I'm copying a file from the current working directory to the document root directory. So copy page dot HTML, index.html. This seems weird because it seems it will copy the file in the same directory, but in fact, it will copy page dot HTML from the current working directory on Docker host to the container working directory, which is slash csr share in genetics HTML. I'm saving and exiting the Dockerfile. And in the current working directory, I'm creating a very simple file called page dot HTML. I am using r direction. So this is a custom engine. Next image, I'm writing something random into the file. And I am building the image Docker, image build minus d ended peg or a name to give to the MIC. For example, my energy next, colon, one dot and dot.me. Build the Docker file in this directory. I'm hitting Enter. It will pull the Debian image from the Docker Hub and then execute each instruction in the Docker file line by line. We see how it's building the image. We are waiting a few seconds. There are more steps and each step is actually aligned in the Docker file. This is step one of 11, step two, step three, and so on. And you see the instructions. Index done. The custom image was built Enrique seat by running Docker image ls. Let's start the container from the mixing Docker, container R1 minus the capital P. My energy mix. Column 1.The 0 m dot container he's running. I can connect to the web server using the IP address of the docker host in the published port. Let's see the exposed part. The sun. Heat was chosen randomly because I used the capital B option when starting the container nbc dot contents of page dot HTML that was copied to index.html in the document root of the web server. 16. Persistent Data: Volumes: Let's start talking about persistent data. By default, all files created inside the container are stored on the writable container layer. This means that the data doesn't persist when the container no longer exists, and it can be difficult to get the data out of the container if another process needs it. Docker has two options for the containers to store files in the host machine so that, that the files are persistent even after the containers stop volumes and bind the monks. In this lecture, I will show you how to use volumes, see severe preferrable over bind monks. While bind monks are dependent on the directory structure and operating system of the host machine. Volumes are completely managed by Docker. Volumes are the best way to persistent data in Docker. So volume is a persistent directory of our container. A mapping between a directory on the docker host and a directory in the container. We create the volume in the Docker file using the volume instruction or using the VIP option when starting the container. When you mount a volume, eat may be named or anonymous. Anonymous volumes are mapped given an explicit name when they are first mounted into a container. So docker gives them or end them name that is guaranteed to be unique within a given docker host. Let's create a new volume by running docker volume, create in the name of the volume, let's say my site. To list all volumes run docker volume Ls into inspector volume around Docker volume, inspect in the name of the volume. We save that to the directory on the docker host that will be used as a persistent won by the container is sludge var lib Docker volumes mysite underline data. When you want to remove a volume around Docker volume. In the name of the volume, my site. I'm not removing it. And the darker volume, boron. We'll remove all unused volumes. Let's start the engine next container with the volume called the mysite event will be used as the document root of the web server. So I running docker container R1 minus d minus, minus name, my web app. Minus BAT, colon 80 minus v, The name of the volume, my site, colon, the directory Honda container, where the volume will be mounted. So ESR share MG. Next HTML. This is the document root of nx, where the website will reside in the name of Deming's MG. Next, the container is running. Now I'm copying a file to the volumes directory to see that engine X has access to it to make it fast and keep it simple, I'll copy the file. So CP, ETC, backside, var lib, Docker volumes. My site underline data. In time copying the file as index.html. And I have to run the command as root because the UN privileged user doesn't have access to this directory. The file was copied. Normally, you copy your website or your web application to volumes directory. In democracy, seeing the website. And we see that the contents from the volumes directory was served by endemics to the client, to the browser. Alright, in this lecture, you've just learned how to use volumes as persistent data in Docker.