What You Need To Know To Start Creating Containers
Do you know the famous phrase It works on my machine
?
Yeah, forget about it, with Docker it is not an excuse anymore. Docker allows you to locally run the same (or almost the same) environment which will be used in production.
So let’s get started understanding what docker is and what docker is not.
Docker is…
In my opinion, Docker is one of the greatest inventions of the XXI century, but we’re not here to discuss my opinion, we’re here to read technical content.
Docker is a computer program that performs operating-system-level virtualization, also known as “containerization”.
More than that, Docker is a popular tool to make it easier to build, deploy and run applications using containers. Containers allow us to package all the things that our application needs like such as libraries and other dependencies and ship it all as a single package. In this way, our application can be run on any machine and have the same behavior.
Docker was first released in 2013, only 5 years ago, but it is already used by a lot of companies, like: Spotify, The New York Times, PayPal, Uber and more (https://www.contino.io/insights/whos-using-docker).
Last but not least, Docker is open source: https://github.com/docker. ❤️
Docker is not…
Docker is not a virtual machine (VM).
A Docker container, unlike a virtual machine, does not require or include a separate operating system. Instead, it relies on the kernel’s functionality and uses resource isolation for CPU and memory, and separate namespaces to isolate the application’s view of the operating system.
Based on the short description above, the following image shows a comparison between virtual machines and Docker containers.
As we can see, Docker containers are simpler than virtual machines and using it we can avoid the overhead of starting and maintaining VMs.
As this is a hands-on tutorial, I will not go deep on how Docker works under the hood. If you want to learn more about it I suggest you read the Docker documentation.
Hands-on
Now that we have learned what is Docker, let’s start the hands-on tutorial.
Installation
Since the installation depends on your operating system, we will not cover it on this tutorial. To install Docker on your OS please follow the official docs:
Hello World
With Docker properly installed and running, let’s start creating containers.
The “Hello World” in Docker is simple like that:
$ docker run hello-world
Unable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-world9db2ca6ccae0: Pull completeDigest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdcStatus: Downloaded newer image for hello-world:latest
Hello from Docker!This message shows that your installation appears to be working correctly....
As you can see, it shows the following message:
Unable to find image ‘hello-world:latest’ locally
It means you haven’t an image called “hello-world” locally so it will automatically pull from Docker hub.
Docker hub is basically:
A cloud-based registry service which allows you to link to code repositories, build your images and test them, stores manually pushed images, and links to Docker Cloud so you can deploy images to your hosts. It provides a centralized resource for container image discovery, distribution and change management, user and team collaboration, and workflow automation throughout the development pipeline.
After pulling the hello-world
image, it will run the container and will show a Hello from Docker!
message with some other information.
Congratulations, you have run a “Hello World” in Docker!