Summary
Highlights
When you run code on your machine, it might work perfectly, but fail on another person's machine. This is often due to differences in software versions (e.g., Node.js 18 vs. Node.js 14) or even entirely different operating systems (Windows vs. Linux), leading to numerous errors.
The first solution was virtual machines (VMs). A VM packages the entire operating system along with all required software and configurations, creating a complete 'snapshot'. While this solved compatibility issues, VMs are heavy, slow to run, and consume significant storage space due to copying the whole OS.
Docker emerged as an improved solution. Instead of packaging the entire operating system, Docker only packages the application and its direct dependencies. This makes the package (called a Docker image) much lighter and faster to run. When an image is run, it becomes a container, which operates on a Docker engine without needing a full OS.
Docker ensures that your code runs consistently across any machine with Docker installed, guaranteeing reliability. To start using Docker, you need to download and install Docker Desktop from docker.com, choosing the version appropriate for your operating system (e.g., Docker for Windows).
For a project (e.g., a Node.js application), you create a 'Dockerfile' which contains instructions on how to build the Docker image. This file specifies what dependencies to include and how to set up the project. You then use the command 'docker build' in the terminal to create the image. To run the application, you can either click the play button in Docker Desktop or use 'docker run' in the terminal to create and start a container from the image.