Introduction
Welcome ๐ to this blog. If you want to learn about Docker and are a complete beginner, you came to the right place. This blog series will cover everything from the very beginning to the end. This blog post will discuss what a container is, what Docker is, why Docker is necessary, and much more. So please stay with us until the end.
In software or application development we always have to face this problem:
"It works on my machine problem"
The main reasons for this problem are missing tools, different configurations, and hardware dependencies on different platforms.
Docker and container are the solutions to this problem.
Why we need Docker & Containers?
Suppose, my friend David and I are building a Flask web application I am using Ubuntu 22._ LTS and he is using Windows 11. I built the web app with some dependencies(e.g., Python version, Flask version, some run commands etc.) when I zipped the project folder and sent it to David, he called me and said It's not working on my machine then I replied It works on my machine problem. Can you guess why this happened?
[Think about it Comment below the answer]
The reason this happens is because of missing dependencies or conflicting dependencies. The simple meaning is that in the David system, there is a possibility that the dependency is not present(installed) or the version is not the same as my system's version. Then in this scenario, Docker and containers came into the picture.
Containers
Containers are like little boxes that hold an app and everything it needs to run, like tools and instructions. They help the app work the same way on any computer, without getting mixed up with other apps.
Don't confuse it with virtual machines, virtual machines are different things. Suppose in terms of the house, think of a virtual machine (VM) as a big house where each app gets its own full house with walls, a kitchen, and a bathroomโit takes up a lot of space and needs a lot of work to build.
A container is like a small apartment in a big building. Each app gets its own room, but they share the walls and the buildingโs kitchen and bathroom, so itโs quicker and uses less space.
Docker
Docker is a platform that allows developers to package applications and their dependencies into lightweight, portable containers. These containers run consistently across different environments, providing isolation and ensuring that the application functions the same on any system that supports Docker.
Installation
In Windows
You can download the exe file directly from the official website.
And install it manually.
In Linux
Step 1: Set up Docker apt repository
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
Step 2: Install the Docker package
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 3: Verify that the installation
sudo docker run hello-world
Conclusion
In this blog, we explored the basics of Docker and containers, highlighting their role in solving the "it works on my machine" problem by providing consistent application performance across environments. Containers are lightweight, efficient, and simpler to use than virtual machines, making them a valuable tool for developers.
Hire me: ankursingh91002@gmail.com
LinkedIn
Twitter
Top comments (0)