Today we are going to introduce the Docker Installation. So, this will be the first lesson we will start discussing Docker.
Initially, we will introduce some theory, and then we’ll demonstrate the installation. In this way, we will raise a Docker machine on an image.
Next, we will compare virtual machines and the individual differences between Docker and virtual machines.
Thus, we will be able to present the correct understanding and enable the identification of the usability of Docker for different projects.
Installing Docker
We can install Docker on Mac, Windows, and various Linux distributions. Consequently, installation of Docker is quick and easy.
The docker website also presents an installation template for each operating system.
In this post, we will introduce the installation of Docker on Linux. In addition, we have an installation video; click HERE.
For those who want to install Docker on Windows or Mac we leave the Links at the end of this Post .
Installing Docker on Linux
Initially, we need to check if we have installed Docker before. If we have already installed it, let us remove the old installation with the command below.
Alternatively, we can choose to use the Portainer; click HERE.
sudo apt-get remove docker docker-engine docker.io containerd runc
Then you will remove any Docker reminiscence you have on your machine. Assuming you already installed. Then we will use the command below to update the repositories.
sudo apt-get update
After that, we’ll start installing the necessary packages and point to the new repository.
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
After that, we’ll update the repositories again and then install the Docker packages.
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Docker is now installed on your machine.
An alternative way to install Docker
The second way of installing Docker uses the Ubuntu default repository. Thus, some users prefer this way of installation, as they argue that it tends to be more stable.
However, other users prefer the first way of installation as we can purchase the latest version of Docker. So, it is up to the user to decide which form of installation to use.
For this second way of installation we will use the command to update the repository and then install the docker.io package.
sudo apt-get update
sudo apt-get install docker.io
Testing the Docker Installation
Let us now start a container called Hello-World. That way, we will know if the installation went satisfactorily.
So, let us use the command below, and we will see a screen similar to the figure below.
sudo docker run hello-world
Download a Docker Image
Now let us look for an image in the Docker repository. Next, let us download the image. Then, we use the docker search command to search for images.
It is noteworthy that we must give priority to official images. Thus, we can check the OFFICIAL column to find the official images and check if the image has an “OK”.
Let's use a debian image.
sudo docker search debian
Okay Juliana, what’s the next step?
Now let’s download the image using the docker pull command.
sudo docker pull debian
Run the Docker Container
Now let’s run a container using the image we downloaded. To do this, let’s use the docker run command.
sudo docker run -it debian
“-it” = The “it” option indicates that we are going to use an interactive terminal.
“debian” = The image we downloaded.
We will see a screen similar to the one in the figure below.
Next, let’s update the repositories inside the container and then install net-tools so we can have access to some commands like ifconfig.
apt-get update
apt-get install net-tools
Checking the network within the container
Now let us check the container’s IP using the ifconfig command (inside the container).
For that, we must have installed the net-tools package inside the container. Next, let us check the routing table using the netstat command.
Therefore, we can check the IP of our container and the routing table.
It is noteworthy that, in this network model, the container has access to the internet because it sends it to the host machine.
This machine performs an address translation to forward traffic to the internet.
ifconfig
netstat -rn
Viewing our Docker Containers
We can check which containers are used and which ones are running using the command docker ps -a.
sudo docker ps -a
To shut down a container, we can use the sudo docker stop command and then the container ID. Let’s look at the example below.
sudo docker stop 0bc339cfeb67
Alternatively, we can use the exit command inside the container.
exit
Install Docker on Windows or MAC
https://docs.docker.com/desktop/windows/install/
https://docs.docker.com/desktop/mac/install/
What is Docker? What is Container?
I am a Docker enthusiast and that is because Docker allows networking and programming projects to be started in a specific configuration and later replicated easily.
Okay Juliana, you have been talking a lot about Docker. However, what is Docker? Also, what is a container? First, we must keep in mind that if we are going to talk about Docker, we must talk about the container.
So, in a simplified way, we can think of a module that packages dependencies and applications, allowing them to be executed in different environments.
In this case, we are describing a little of the theory. Consequently, the Docker image contains the tools, libraries, and settings the applications need.
So what would be the cases where Docker would be interesting?
Let us take an example from a programmer. So, let us assume that the programmer is making an application in Python.
Consequently, this programmer included several libraries and prepared the entire environment for that application.
Then, the programmer can generate a Docker image with the entire environment configured.
If the programmer wants others to access his application, he can pass the corresponding Docker image.
This example may be easier to notice if we imagine that you work with a group of developers.
Then you can pass this Docker image, and they will use it in their own environment without worrying about dependencies and libraries.
Now, let us use an example from the computer networking area. This way, we could run a different environment and include different application servers.
Also, Docker is suitable for security. Therefore, we can use Docker to create an extra layer of security.
Another example of using Docker is in Pentest practices. Thus, some users like to use Docker for pentest due to the easy installation of security analysis tools.
Furthermore, the user can delete the container and discard collected information after initializing the Docker container and performing the security analysis.
Difference between Docker Image and Docker Container
The container is running a Docker image. Therefore, when you take a Docker image and run it, it becomes a container. So, soon we will see all this in practice.
The container works in isolation and independently of the infrastructure. Thus, this container isolation provides interesting results to meet different applications.
Comparing Docker Containers and Virtual Machines
Here we present a comparison between Docker containers and virtual machines. So, let us compare and talk about each of the differences.
However, first, let us check the infrastructure of virtual machines and Docker containers.
Virtual machines can act directly on top of the Hypervisor. So, in virtual machines, we have the infrastructure as the first layer.
Then, we have the operating system as the next layer. Then, finally, we have the Hypervisor.
First Comparison between Docker and Virtual Machine
Okay, what about the Docker container? In the case of Docker, this runs above the operating system. Consequently, it is the Docker that will host the containers.
So, we have the host system kernel share in the Docker container. Consequently, we will create a container based on the Linux kernel if we use Linux.
Alternatively, if we use Windows, we will create Windows-based containers.
However, there are applications to emulate different operating environments. Thus, we can use a Linux container on a Windows machine using such applications.
In contrast, each virtual machine can have its operating system independently of the host operating system.
Therefore, we can use a host system that uses Linux and creates a virtual machine with Windows, Linux, or BSD.
Regardless, we can raise several different machines with different operating systems. Then, we can say that this was the first comparison.
Docker Containers are Lightweight and Fast to Boot
Docker containers are lighter and smaller. Also, they have a quick start.
So, for example, when we generate a Docker image, this is much smaller than generating a virtual machine image.
Consequently, in terms of resource consumption, Docker is excellent.
Thus, a Docker container presents a low consumption of resources and a quick startup compared to virtual machines.
So if we want to raise an APACHE2 on our server, we can quickly start the container with APACHE2.
Docker containers are easier to configure
The configuration draws attention when comparing containers and virtual machines.
In addition, we can automate specific configuration tasks that are less likely to fail in these configurations.
Therefore, the Docker containers have been used widely due to their easy configuration.
Docker Containers Have Less Isolation
On the other hand, not everything is perfect regarding the Docker container. For example, using virtual machines will provide us with more excellent isolation.
Then, we can assume that since the virtual machine does not share the host machine’s kernel, we have better isolation between the two machines.
Thus, this better isolation also occurs in terms of the consumption of resources. That is, we can guarantee better resource isolation using the virtual machine.
Linux container inside Windows host
What if I need to run a container from another operating system?
Our friend Cass has this question: We are using a Windows machine and want to run a Linux container. How do we do it?
One of the ways to do this is to use Hypervisor and a virtual machine; inside that virtual machine, we can use Docker.
Alternatively you can also use alternative applications like WSL (Windows Subsystem for Linux).
So, let us assume the following example: We are using Windows as a host machine and a virtual machine with Linux with Docker inside.
Therefore, we can raise containers within this Linux virtual machine from that Docker.
There is no sentence like “I am using Windows, and I can only raise a Docker container with Windows?”. So the answer is no.
Therefore, if we use this hybrid form with virtual machines or applications like WSL, will we be able to work with different operating systems.
- See more posts from our Docker tutorial
- Article 01 – Docker Installation
- Article 02 – Docker: Handling Containers
- Article 03 – Docker: Installing servers in Docker
- Article 04 – Portainer : Installation and Configuration
Read more:
- Portainer: Installation and Configuration
- Blockchain – The technology behind innovation
- NMAP: Advanced Scan
Juliana Mascarenhas
Data Scientist and Master in Computer Modeling by LNCC.
Computer Engineer