Today I wanted to show you just how easy it is to get started with containers. If you aren’t familiar with the concept of containers, refer to my previous post “Living in a Containerized World“. This post is going to focus on getting started with Docker. I wanted to give you the fundamentals around getting Docker installed and how to get your first container up and running. This particular post is for those who have never worked with containers and are curious. This is all about containers made easy.
Installation
Since my workstation is running Windows, we are going to focus on Docker for Windows. However, if you use a Mac, you can install Docker for Mac as well. There are some requirements that you need to meet for your windows system. It needs to be running 64bit Windows 10 Pro, Enterprise, or Education edition with the Anniversary Update installed. If you don’t have the update installed you will be notified. In addition, you need to enable Hyper-V. You will need to reboot your system after enabling Hyper-V. If not enabled, the Docker for Windows installer will enable it for you.
You will notice that there is also something called Docker Toolbox. There is a version for Windows and Mac. If your system does not support the prerequisites, you can use the toolbox install which uses Oracle Virtual Box. Click here for the Docker Toolbox downloads.
Step 1: Now that you have met the prereqs, download Docker for Windows here. This includes Docker Engine, Docker CLI client, Docker Compose, and Docker Machine.
Step 2: Double-click InstallDocker.msi, accept the license agreement, and click Install. You may get a UAC prompt to allow this app to make changes to your device. Click Yes to continue. Click Finish to launch Docker. Once initialization is done, you will get a popup stating “Docker is now up and running”.
In addition, you will see the whale in the status bar. Right-click the whale and select About Docker to see the version. In addition you can check for updates, change the settings for startup, shared drives, how much CPU and memory to allocate, network settings, and reset to factory default. You can also access Kitematic from here. More about Kitematic later.
Operation
Now that was too easy. Now that we have Docker installed and running, lets play. The good thing is you can open your favorite shell, be it PowerShell, or CMD.exe to run the commands. Let’s check the versions of docker, docker-compose, and docker-machine. If I type “docker version” I can see the client and server versions as well as the OS/Architecture. Likewise I can type “docker-compose version” and “docker-machine version”.
If I run “docker info” I can see how many containers I have as well as the ones that are running, paused, or stopped. I can see the number of images as well as a lot more info.
Now lets try to pull an image from Docker Hub. What is Docker Hub you ask? Docker Hub is a cloud based registry service for public or private content. It provides a centralized resource for container image discovery, distribution and change management, user and team collaboration, and workflow automation throughout the development pipeline. Now let’s type “docker run hello-world”. Congratulations, you just deployed your first container. Since the image is not local, it pulls it from Docker Hub.
Now lets try something a bit more fun and interesting. Let’s deploy a container running nginx webserver and then validate that we can see it in our browser. Type “docker run -d -p 80:80 –name webserver nginx”. Now point your browser to http://localhost. Simple, yes? The -d is for detached mode and -p is for port.
Now if we type “docker ps” we can see that there is one container running. If we type “docker stop xxx”, (xxx being the first few letters of the Container ID), the container will stop running and we lose access to our site. Now if we type “docker ps” again nothing shows. That’s because there are no running containers. To see all containers type “docker ps -a”. Now you can see the container and the status shows as “Exited”. Typing “docker start xxx” and the status is now “Up”.
Now let’s clean up and stop and remove the containers that we deployed. Type “docker rm -f webserver” to stop and remove a running container. Now the container is gone but the image is still there. Type “docker images” to see all the local images. If you have no intention of using the image again go ahead and delete it. You can do so by typing “docker rmi nginx”.
Previously we mentioned Kitematic. So what is this? Kitematic is compatible with Docker for Windows and can be used as a graphical interface to manage containers. If interested, you can click here for more info.
Summary
Now that you have Docker installed and have deployed a few containers, hopefully you are beginning to see the power of containers. You surely wouldn’t be able to deploy a VM that fast. We have only scratched the surface of containers up to this point. Stay tuned as we will start to get a little more familiar with some of the other components and tooling.