In this video, learn about the footprint of a Nano container along with the process to create, start, and save Windows containers with custom applications.
- [Instructor] This course is geared mainly towards network administrators. I've talked about some of the sysadmin benefits of containers in terms of low overhead and portability. In this segment, I want to step through the process of creating a new Windows container, and along the way, I want to demonstrate just why containers are so appealing to developers. I'm starting out on this Windows 2016 server that I installed with the desktop experience specifically so that I could show you a couple of details about new containers.
I've already installed the Containers feature, as well as the docker module, and I've already pulled the base images for Nanoserver and Windows Server Core. What I want to do now is open a file browser where I'm going to go to the C drive, the Program Data folder, and inside the Docker directory, I'm going to open up Containers. I have the base images installed, but I haven't run any containers. I'm going to move this off to the left so we can see what happens when we stand up a container.
Next, I'm going to open PowerShell, once again as an administrator, and I'm going to move this slightly off to the right so that we can see that container's directory. The first command that I'm going to run will show us what images already exist on our server. This command shows that we have the latest version of Windows Server Core and Nanoserver published by Microsoft only 13 days ago.
So what I want to do now is, I want to run an instance of that Nanoserver image. I'm going to stand up a container using the docker command Run. The first thing I need to specify is that this is going to be an interactive container and that I want to use a teletype or the traditional screen and keyboard as a console to interact with this container. The image that I want to stand up in my container is the Microsoft Nanoserver image, and finally, I need to specify what application I want to run in that container when I start it up.
Now, my intent is to interact with this container, so the application I want to run is the command interpreter so that I can have a prompt and I can type commands into this Nanoserver. You'll notice that immediately, a folder was created over here in the directory on my hard drive, and I am now at a command prompt inside this Nanoserver container. I'm going to create a very small PowerShell script while I'm here.
Inside PowerShell, I'm going to add content to a new file, let's save it on the root of C, and call it greetings.ps1. And what I want to add to that file is a PowerShell cmdlet of write host, and what I want that cmdlet to display is welcome to my first Nano server container.
Close quote on my content, single quote to end the write host, and now I can hit Enter. I guess I could have used Hello World, but that seems a little cliche. Not a revolutionary new program here, but it meets our purposes. So now I'm going to type Exit to get out of this container. Now I'm back in PowerShell on my host server. Sometimes it can be tricky to keep track of these. If you're supposed to be on your host machine and you can't tell, you can always close PowerShell and open it right back up again.
But I'm confident that I'm back on the host server in PowerShell, and from here, I'm going to take a look at the containers that are running on my server right now. The command to do that is docker ps space dash A. That will show me all containers that are currently running on my server, so even though I left that command prompt, this Microsoft Nanoserver, with the command prompt open, is still up and running.
If I had left a network application deployed to my network running on that server instead of just a command prompt, then that would continue to be available to my network users. But what I'm interested in doing here is more than just propping up a container. I actually want to commit these changes to a whole new image that has my application as well as the supporting layers of the Nanoserver base image. The command to do that is docker commit.
What you need to type after commit is the container ID, and you can simply look at this and retype it. What I like to do is select that ID and then from this menu, I'm going to select Edit and Copy, and then here where I'm typing, I can simply hit Control V to paste that ID, eliminating the opportunity for me to mess it up as I try to type that in. And then I need to assign this new image a name.
I'm going to name mine trialone. This name needs to be all lowercase letters with no spaces. Once that image has been created, I can run docker images again, and I can see that in addition to the Nanoserver and the Windows Server images that I downloaded in the previous segment, my trialone image is here ready to use, and it says that this image in its entirety, all layers, takes just over one gig of hard drive space.
If I want to test this image, I can go ahead and use the docker run command to load that new image. Let me go ahead and clear the screen to buy us back some real estate so we can see what it does. I'm going to type docker run. This time I'm not interested in interacting with the server. In fact, I'm only running this container to see if my program works. As soon as I'm done with this test, I want the container to delete itself, but leave the image on the server.
So I'm going to add the parameter here of dash dash rm. That will have the effect that, as soon as this session is done, the container will be removed from this server. I'm going to enter the name of the image, and then I'm going to specify the command or the application that I want it to run. I want it to run PowerShell, c colon backslash greetings.ps1.
You can see that a new container was created, and then as soon as the application was complete and my message was displayed, that container was done and it was removed. So let's review what just happened. I created a program development and testing environment without requiring dedicated hardware or even a new virtual machine, and I did it in a matter of seconds. The environment was separate and had no impact on any other container or on the host machine other than the creation of this directory.
If I wanted to build onto my script, I could repeat this same process, and each time I used the docker commit command, I could assign a new name. All of this was done without the licensing of operating system installs. It was also done without the time and space requirement of creating virtual machines. The images that were created are more complete than simply checkpoints in a Hyper-V manager, and when I look at the footprint on the hard drive, it's pretty small.
If I look at the properties of this directory, I find that I'm taking up a total of 12k on the hard drive. The rest of that one gig that we saw previously was the foundation layer, the Windows Nanoserver image. The actual container itself is only 4k in size, taking up 12k on the disk. Containers are something that we as sysadmins should be encouraging and facilitating for our development teams.
- Physical host environments
- Virtual host environments
- Installing and creating Windows containers
- Creating Hyper-V containers
- Creating, tagging, and pushing images
- Removing images
- Configuring startup options
- Working with PowerShell, Docker daemon, and Azure
- Managing container networking
- Managing data volumes, resources, and repositories