In this complete tutorial, we will introduce Docker installation on Linux, run our first containers from an image, inspect container networking, and explore essential management commands.
In addition to the practical installation steps, we will also cover the core concepts behind containers and compare Docker with traditional virtual machines so you can identify the best approach for your networking, server, and development projects.
Installing Docker
Docker can be quickly and easily installed on macOS, Windows, and various Linux distributions. The official Docker website also provides dedicated installation guides for each operating system.
In this post, we will demonstrate how to install Docker on Linux. You can also watch our step-by-step Docker installation video tutorial on YouTube.
For those who want to install Docker on Windows or Mac, we have included the official links further down in this post.
Method 1: Installing Docker on Linux (Ubuntu Default Repository)
This first method uses Ubuntu’s default repository. Many users prefer this approach because the packages are maintained by the distribution’s community and tend to be very stable.
To install the Docker engine (docker.io) and the Docker Compose v2 plugin, update your package index and run the command below:
sudo apt update && sudo apt install docker.io docker-compose-v2 -y

Docker is now installed on your machine. If you prefer to manage your containers through a graphical web interface, check out our guide on Portainer: Installation and Configuration.
However, other users prefer the alternative installation method directly from Docker’s official repository to get the latest version of Docker. You can choose whichever option best fits your environment.
Method 2: An Alternative Way to Install Docker (Official Repository)
First, if you have older or conflicting Docker packages installed on your machine, remove them using the command below:
sudo apt-get remove docker docker-engine docker.io containerd runc
Next, update the repository index and install the prerequisite packages that allow apt to use repositories over HTTPS:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release -y
Download and add Docker’s official GPG key:
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
Now, point to the official Docker repository by running:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
After that, update the repositories again and install the official Docker packages:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Docker is now installed and ready to run on your machine.
Testing the Docker Installation
Let’s start a test container called hello-world to confirm that the installation was successful. Run the command below and you will see an output similar to the figure that follows:
sudo docker run hello-world

Download a Docker Image
Now let’s search for an image in the Docker Hub repository and download it. We use the docker search command to look for available images.
As a best practice, always prioritize official images by checking the OFFICIAL column and verifying that it displays [OK]. Let’s search for a Debian image:
sudo docker search debian

What is 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 start a container using the image we just downloaded with the docker run command:
sudo docker run -it debian
-it: Allocates an interactive terminal session inside the container.debian: Specifies the image we downloaded.
You will see a terminal prompt similar to the figure below:

Next, let’s update the package repositories inside the container and install net-tools so we can use network commands such as ifconfig and netstat:
apt-get update && apt-get install net-tools -y


Checking the Network Within the Container
With the net-tools package installed, let’s inspect the container’s IP address using the ifconfig command and view its routing table using netstat -rn.
In this default networking mode (Bridge), the container accesses the internet by sending packets to the host machine, which performs Network Address Translation (NAT) to forward traffic to the external network:
ifconfig
netstat -rn


Viewing Our Docker Containers
We can check all existing containers and see which ones are currently running by executing the docker ps -a command on the host:
sudo docker ps -a

To stop a running container from the host terminal, use sudo docker stop followed by the container ID:
sudo docker stop 0bc339cfeb67
Alternatively, you can type the exit command directly inside the container’s terminal:
exit
Install Docker on Windows or Mac
What is Docker? What is a Container?
Docker is a powerful tool because it allows networking, server, and software development projects to be packaged in a specific configuration and easily replicated across any environment.

To understand Docker, we first need to understand what a container is. In simple terms, a container is a software unit that packages applications along with all their dependencies, libraries, and settings, allowing them to run reliably across different computing environments.
When is using Docker most beneficial?
- Software Development: Suppose a programmer builds a Python application that relies on several specific libraries. The developer can generate a Docker image with the entire environment pre-configured and share it with the rest of the team, who can run it immediately without worrying about installing dependencies.
- Computer Networking and Servers: Network administrators can spin up isolated lab environments and deploy multiple application servers in seconds with minimal hardware overhead.
- Cybersecurity and Pentesting: Security analysts frequently use Docker to deploy penetration testing and security auditing tools quickly. Once the assessment is complete, they can simply remove the container and cleanly discard the temporary environment.
Difference Between Docker Image and Docker Container
A Docker Container is simply a running instance of a Docker Image. When you take a read-only Docker image template and execute it, it turns into an active container.
Because containers operate in isolation and independently of the underlying infrastructure, they provide consistency and flexibility for deploying diverse applications.
Comparing Docker Containers and Virtual Machines
Let’s compare the architecture of Docker containers and traditional virtual machines (VMs) to understand their key differences.
In a traditional virtual machine setup (such as VirtualBox), we have the physical hardware infrastructure as the first layer, followed by the host operating system, the Hypervisor, and finally a complete guest operating system for each VM.

1. Kernel Sharing vs. Independent OS
Docker runs directly on top of the host operating system and shares the host system’s kernel across its containers. This means that on a Linux host, your containers run using the host’s Linux kernel.
In contrast, each virtual machine runs its own separate operating system and kernel independently of the host. On a single Linux host, a hypervisor can simultaneously run Windows, Linux, and BSD virtual machines.

2. Docker Containers are Lightweight and Fast to Boot
Because Docker images do not bundle a full guest operating system, they are much smaller than virtual machine images. As a result, containers consume far fewer hardware resources and boot up in seconds—making it effortless to spin up services like an Apache web server almost instantaneously.

3. Docker Containers are Easier to Configure
Another major advantage of containers is how easily they can be configured and automated. Using code-based configuration files, teams can automate deployments and significantly reduce human error.

4. Docker Containers Have Less Isolation
On the other hand, virtual machines provide stronger isolation. Because a virtual machine does not share the host machine’s kernel, it offers deeper security and hardware resource isolation between the guest and the physical host.

Running a Linux Container Inside a Windows Host
What if you need to run a container built for another operating system?

Our friend Cacs has a common question: “I am using a Windows machine and want to run a Linux container. How do I do that?”
There are two practical ways to achieve this:
- Use WSL 2 (Windows Subsystem for Linux): Docker Desktop on Windows integrates directly with WSL 2 to run a real Linux kernel seamlessly in the background.
- Use a Virtual Machine (Hybrid Approach): You can run a Linux virtual machine on your Windows host using a Hypervisor (such as VirtualBox or Hyper-V) and install Docker inside that Linux VM.

So you are never restricted to running only Windows containers on a Windows computer—by using WSL 2 or a Linux virtual machine, you can work with Linux containers effortlessly.
- 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








