Learn how to list Docker images currently on the host machine, and how to pull an image from Docker Hub.
- [Narrator] Visual Studio 2015 update three and higher have added Docker support. You can enable it by clicking this checkbox here. But, if you don't know that Visual Studio is going to generate for you, you could end up being in trouble when it comes to modify it. I found the best way to dig in the nuts and bolts of Docker; it's just do it from the command line, so let's go over to the command line and do that now. I'm going to use Power Shell for these demos, but you can use the Ubuntu built-in shell. You can use the regular command window or the get back shell to do any of these commands.
As long as you have Docker installed, any of them will work. The best way to find out if you have Docker installed is to type docker -V in the command line. When you run it, you should see some output like this. In this case, I have Docker 17.12 of the Community edition installed. Your version may vary, but as long as it's above 17, you're probably okay. To list the images that we have currently installed on our host machine, we'll run docker image list.
Now, you'll see, I have one already downloaded. You probably won't have anything here. I've downloaded the Hello World repository so that I could show you what these headers actually mean. For instance, you'll see the repository. This one's called Hello World. The tag. This is actually the latest version of that repository. You can think of it like Get Hub. Your repository and then you can tag different versions of that repository. Then, you'll see the image ID. That's this 15-digit hash right here.
This was created two months ago and its size is 1.85 kilobytes. If you need to get an image that you don't already have on your host machine, you'll pull it from Docker Hub by running docker pull and the image that you want to pull along with its tag; in our case, we'll stick with the nginx and pull down 1.13.8 of the Docker nginx image. When I run this, you'll see it start downloading different layers.
Once the images have been completely downloaded and extracted into the image, the image will get a sha; you'll see it here starting with two, eight, five and you'll see that it downloaded the image for nginx 1.13.8 and if I run my Docker image list again, I'll see that nginx 1.13.8 is there. Now, let's assume that I pulled down the wrong image. Maybe I wanted to use 1.12.2; to remove an image that I already have downloaded onto my host, I can just run docker rmi for remove image and either the name of the image 1.13.8; the name and tag or I can also use the image ID if the repository name or the tag it's too long; then you might think, why would I want to type out that image ID.
The good news is you don't have to type out the whole image ID; just enough of the ID to make it unique in this list. For our purposes, three will work just fine. For regular production work, I tend to stick to the first three characters; 3f8; when I run this, you'll see that it untagged nginx 1.13.8 and the sha that went with it and then you'll also see that it deleted all four of the layers that go with the nginx image. Since no other images on the host machine were using those layers, the host machine can get rid of them.
- Why containers?
- How do containers compare to virtual machines?
- Creating a Dockerfile
- Building an image from a Dockerfile
- Running a container from a new image
- Working with the Docker Compose file format
- Pushing images to Docker Hub