Why Do We Need Docker?
Before we start learning about Docker, it is crucial to understand why exactly we need it — what problems exist in our current software development process that Docker was created to solve.
Let's take a very basic example. Suppose we are trying to develop a Node.js based application. Generally, if we are building a Node.js application, we would have already installed Node on our system. Let's assume we installed Node version 16, and along with that, we are also using MongoDB as a database, so we installed MongoDB version 4.2. This is our local development environment in which we are building our application.
When we talk about personal projects or small-scale projects, we generally don't encounter too many problems. The problems that Docker is designed to solve usually arise in large organizations or when there are many members in a team, all working on the same application.
Let's assume we are working in an organization, in a team, and a new member joins who has a Mac OS system. They now want to replicate the entire setup on their own system so they can also work on the same application. This member is going to manually install all the dependencies one by one. They start with Node — maybe a newer version is available, so they install Node version 20. Similarly, they install MongoDB — maybe a newer version exists, so they install MongoDB version 6. And this is how they set up the entire environment on a different machine.
Common Problems When Replicating Environments
When we try to replicate a local development environment from one machine to another, there are some common problems we can encounter:
- Manual Errors: We are installing dependencies one by one on the new system. In a real-life application with lots of dependencies, there is going to be a lot of room for error.
- Version Mismatch Bugs: A specific part of our application may depend on a specific version of Node.js. If it doesn't get that exact version, there could be bugs in our application.
- OS Compatibility Issues: Some CLI commands used in the original application may work only on a specific operating system (e.g., Linux commands), and when we try to replicate them in a Mac or Windows environment, they may not work the same way.
- Production Server Issues: When we try to replicate the same setup on a production server, the same common errors can occur.
This problem gets harder as the team grows. With two or four people, it's easy to solve. But when talking about larger teams where many members are working on the same application, the development process can become very error-prone.
This gives rise to a very classical problem in software development known as:
"It works on my machine"
It is to solve this specific problem that tools like Docker were needed.