Getting Started With Docker 2023

Hi! My name is GEORGES FOUEJIO. I'm a software Engineer. I use modern tools and bests frameworks to build powerful web/mobile apps. The web development is my passion.
Hey, have you heard of docker? If you haven't, then let me tell you that it's an amazing tool that you should definitely add to your list of tools. But if you're a software developer, you've probably heard about it, either in some forums or in discussions between friends.
In this article, I explain what docker is and I show you how to create your first docker image and launch your first container.
What is Docker?

Docker is a tool to create application containers. That's it! You were expecting something complicated? Well, no. Now I want you to repeat it with me: Docker is a tool to create application containers. Now that this is said, let's see what an application container is.
Application container
An application container is an isolated framework where an application executes (or several but in the majority of cases, it is one application for one container). A container has the advantage of being lighter and runs on a host system, unlike a virtual machine which requires more resources.
Containerization Vs Virtualization
Docker works with a Conteuneurization system and not with Virtualization.
Virtualization allows the mobilization of the resources of a host system to create another virtual system. For example, I am on a windows machine and I need to test a Linux system but I don't want to install it in another partition of my hard disk. Then I can use virtualization with a tool like VirtualBox or VMWare to allocate resources for the virtual system. Here are virtualized processor, the RAM, the hard disk, the network, etc., which mobilizes a significant amount of resources. Isn't it?

Conteuneurization, unlike virtualization, does not run an entire system, but rather it runs an application in its context, which mobilizes just a few resources because the application here only works with what it needs.

Now that we know a little more about containerization and virtualization, let's describe a situation where docker will be useful.
The problem
I cloned a project that consists of a java spring-boot server, a nodeJs server, a Postgres database, a Redis database, and a React frontend; and my boss told me: Come on, run this project, my seasoned developer.
Here it becomes a bit complicated because you have to install java, nodeJs, redis, and the versions to install must correspond to the needs of each. Let's say you are a good developer, you install everything and it works. Now you are asked to deploy all this in a VPS. You still have to install and configure everything in the VPS, maintain the versions, etc. And if you are in a team that some use Linux, some use windows, some use MacOs, and some use Centos, maintaining that can become difficult in the long run. You see where I'm going with this, don't you?
That's where Docker application management comes in.
Thanks, Docker

Thanks to docker, because being on different OS (Mac, Windows, Linux, centos), we can have the same functioning using containerization. For our problem, we could have:
an image for java that we will use to launch a container in which our java spring-boot server will run
an image for nodeJs thanks to which we will launch a container in which our nodeJs server will run
an image for postgres thanks to which we will launch a container in which our relational database server PostgreSQL will run
an image for Redis thanks to which we will launch a container in which our Redis server will run
and finally an image for our React frontend app thanks to which we will launch a container in which our frontend app will run
The big advantage is that these images work everywhere and exactly the same way whatever the operating system, as long as it can run docker, and luckily for us, docker is available on the majority of Os that we use daily, whether Linux, macOS, or Windows.
Images & Containers
These are the two fundamental components of docker. If we have to remember anything, it is this. We will quickly explain these two concepts in the context of docker and then we will move on to the installation of docker.
Docker Container
In Docker, a container is an isolated environment on which an application usually runs. This environment has a file system and contains the bare necessities for its operation. A container is launched from a docker image. To know more about it, check the official docker documentation about docker containers [link].
Docker Image
In docker, an image is a set of configurations that allows launching a container. An image contains everything needed to launch an application. A docker image can therefore be used to launch several instances of containers that will work exactly the same way. To learn more, check the official docker documentation about docker images.

There are two types of docker images:
Public docker images, which are available on the docker hub. public images can be pulled and used by everyone
Private docker images are those that we build ourselves and are not available to the general public.
PS: it is to be noted that an image can be created from another image, which makes it possible to start on something and not to remake the wheel each time. Isn't docker magic?
Docker installation
Installing docker is quite simple, whether you are on mac, windows or Linux. The official doc provides all steps to follow.
For macOS and Windows, You just have to download docker from the official website and then launch the installation.
For Linux, you can use the command prompt. Again, the official docker website gives us the procedure. Just follow the steps described here.
Let's try Docker
The main goal of this article is to make you understand the usefulness of docker. We are going to make a simple use case so that you understand better how it works. We are going to retrieve an image and launch it. We are going to containerize a redis image on our machine.
Redis, which stands for Remote Dictionary Server, is a fast, open source, in-memory, key-value data store. The project started when Salvatore Sanfilippo, the original developer of Redis, wanted to improve the scalability of his Italian startup. From there, he developed Redis, which is now used as a database, cache, message broker, and queue.
Source: aws redis
On windows or mac, once you have installed docker, make sure it is running, then launch your command prompt.
On Linux, check with:
sudo service docker status

Once this is done, go to docker hub, and in the search bar, search for redis

Click on redis official image, now you have

Now, in your terminal, run this command below to get redis image
docker pull redis
you will see something like this during the pulling

After that, you can see the list of all available images in your PC with the command:
docker images

Now let's create our docker container from our redis image
docker run -d redis
-d is for detached mode, which means it runs in the background
At this point, the container is created and it is running. We can check with
docker ps

As you can see, my container is running since 18 hours, for you, it's probably since a few minutes.
Now let's get inside our container and use our redis. Run this command below
docker exec -it adoring_babbage bash
adoring_babbage is the name of the container that has automatically been generated by docker when creating our container with docker run

Now, we are really inside our container and we can type some unix command like ls, pwd, cd, etc... Let's run redis by typing redis-cli command in our container.

And voilà. We are running redis on our PC using Docker. That's cool.
Summary
And here we are, we have installed and used redis with docker, without the need to install it on our PC. Now that you have a better understanding of what docker is and what it can do, I invite you to learn more about it. Docker is a great tool and it would be a shame to do without it. This article was meant to be a getting started and therefore quite simple. If you liked it, put a heart to encourage me and share. I'll be back soon with more articles about docker and others subjects.