Docker is a virtualization technology that operates at the OS level. Cloud native applications are packaged, distributed, and run as containers. The aim of this video is to teach the Docker basics required throughout this section.
- [Narrator] So this third section of the course is all about Docker. It's an introduction to Docker and to Go microservice containerization. So in this section we're going to take a look at the basic Docker workflow and some basic Docker commands that should get you through this course. Next up we're going to build a Docker image for our little Go microservice we've built previously. We've then let out containerized Go microservice run locally and play around with it a little.
And finally, we're going to build an improved Docker image and I'm going to show you how you can use Docker compose to fire up this image in addition to a few other services maybe. So this is a lot of content, so let's get started. In this video I will talk about the basic Docker workflow and some basic Docker commands you need to know to get throughout this course. So in this video we're going to take a look at the difference between hardware and operating system virtualization.
We then talk about Docker images and containers. Next up, we will talk about the Docker workflow, and finally I'm going to show you some basic Docker commands you need to know. So what's this different between hardware and operating system virtualization? So I guess all of you have probably used virtual machines, right? And virtual machines are all about hardware virtualization. So what you usually have is, well a virtual machine that consists of virtual hardware, a full operating system, some operating system libraries, and your application, and this virtual machine usually runs on real hardware.
So this gives you quite a strong isolation compared to other approaches. But on the other hand to fire up such a virtual machine, this is usually quite slow because you're firing up a whole computer. So the difference now is operating system virtualization and Docker is OS virtualization. So here you only have operating system libraries and your application, and this builds the so-called container.
Now this container runs on your host operating system that then provides access to maybe virtual hardware or real hardware. So as you can see the private copy is a lot smaller here because you only have the application and operating system libraries. You have neither a runtime overhead because it only takes the application to fire up and nothing else, the operating system is already running. So have very short start-up times off your applications compared to hardware virtualization.
Now this is what makes Docker so strong. Now important to know is the difference between Docker images and containers, and you shouldn't get them mixed up. Now Docker images on the left hand side, they're the resting and transportable representation. Such an image consists of multiple file system layers, so maybe as you see here in those graphics, you have a base image, maybe an Ubuntu, as the base file system.
And on top of this base image you put derived images. Layer by layer, okay, as many as you like. At the very top layer what you usually have is your application. If you take such an image and you run it, then you will get the container. So the container is the running state of an image. So what happens here? Well first of all, all those base image layers, they're kind of merged into one union file system.
And on top of this you maybe have some container state which is obviously read write, that your application leaves once it's running in this container. So this container runs as long as the entry point process runs. So it runs as long as your application runs. If you application dies or if application stops, the container also stops. What it can do is to commit this container state into a new image. So you might ask where you can get those images from.
Well, usually you get those images from Docker registries. And the Docker hub is the public repository for loads of Docker images. So if you're looking for the golang Docker image for example, you see here the very first row, you can go to Docker hub and download this Docker base image. We're going to see that later. So this graphics here is the real basic Docker workflow.
It all starts with a Docker file, see that on the left hand side. And the Docker file is a real basic text file in the end where you put certain commands in to build your Docker image. So the command you will then later use is the build command to get your image. From the image we've also seen that you can use the Run command to get the running container. If you have such a container you can stop, you can start, or restart your container.
Also possible is to take a running container and to take the state of the container and to commit it into a new image. Once you're done with all that you can tag an image. Tagging is like giving a version number to your image. Once you've done that you can then use the Push command to push it to a remote Docker registry. Also, you can use the Pull command to pull other images from this Docker registry into your local computer and into your local Docker instance.
And also there are some save and load commands that will enable you to do some backup of your images. So this is the basic Docker workflow you should be aware of. And in here I have some basic Docker commands. I can use the docker build command to build a Docker image from the Docker file in the current directory. If you issue docker images it prints out all the images. You use docker run to run an image.
You can use docker ps to have a list of all running containers. You can use docker kill to terminate a container. You will use docker rm to remove a container, or maybe docker rmi to remove a local image. So let's see that in action. So here I have my console. So you see I issues Docker images to display all the images that are on my local Docker host at the moment.
So you see here I have an nginx, I have a golang image, 1.7.4, and even smaller golang image based on alpine. You see here the size, 240 megabytes. And here I have some later version of our golang. So if you're wondering where you can get those images from, well I showed you, you can use Docker hub. And you see here, Docker hub provides, well, it's the central registry for docker images.
And you see here we have the official repository for golang. And those here are the different supported tags and versions that are currently offered. So you see here 1.7.5-alpine for example. So we can click in here, and you see the basic docker file that has been used to build this image. So if you want a pull command, docker pull.
Now obviously this docker pull command doesn't do a lot at the moment because I already have this docker image in my repository. So next up, we will build a naive Docker image for our Go microservice, see you then.
This course was created and produced by Packt Publishing. We are honored to host this training in our library.
- Implementing Go HTTP Server
- JSON marshalling and unmarshalling of Go structs
- Implementing a simple REST API
- Using Docker workflows and commands
- Building a naïve Docker image
- Running a containerized Go microservice
- Kubernetes architecture and concepts
- Deploying a Go microservice to Kubernetes
- Implementing service descriptors
- Performing rolling updates