Over dinner during the last Christmas holiday, my cousin, who works in maritime logistics, explained his job managing shipping containers. The next day, during a car ride with my parents, I casually mentioned that software engineers also use the concept of "containers" to deliver applications.
My parents asked me to explain. That innocent question sparked an hour-long explanation of Docker in the backseat π
It turned out to be a rewarding experience because it challenged how well I understood it. So, I thought I'd recreate that conversation here (with visuals!) to help others understand Docker.
What's Docker?
βDocker? What's that?β my parents asked, intrigued.
Docker is a program you install on your computer. It lets you package your app and everything it needs (code, libraries, settings) into a unit of software called a container.
Developers use Docker to package applications so they can run reliably and consistently.
But why do we need Docker?
βOkay, that sounds interesting,β my parents asked, βbut what problem does it actually solve?β
The main benefits of using Docker are consistency and speed.
In shipping logistics, containers are used to transport goods from one place to another. The point of using containers is consistency. No matter whatβs inside (a couch, TVs, or shoes), it all fits into a standard-sized box that ships easily.
In software engineering, we have a similar concept.
When we deploy an application, we want to package everything it needs - its code, configuration, and dependencies (like libraries) - into a box that can run anywhere.
π¦ Physical Container π³ Docker Container
ββββββββββββββββββββ βββββββββββββββββββββ
π’ Shipping Box π¦ Docker Container
π§Ύ Packing List π§± Docker Image
π₯οΈ TVs π» App Code
π Shoes π Libraries
π Books βοΈ Config Files
π½οΈ Dishes π§ͺ Dependencies
π Secure + Sealed π Isolated + Portable
π Easy to Transport π¦ Easy to Deploy
π Standard Size π Consistent Environment
β‘οΈ Goal: Standardize Delivery β¬
οΈ
π³οΈ Goods π§βπ» Software
We work with multiple environments in software engineering: for example, the test environment or the production environment with which customers interact. Docker ensures that your application behaves the same, no matter in which environment it runs.
Unlike older methods like Virtual Machines, Docker doesnβt need to simulate a full operating system, so it's fast.
Wait... Whatβs a Virtual Machine?
My mom looked back and said: βVirtual machine? You lost us there, honey.β
Fair enough! π
A virtual machine (VM) allows a physical computer to simulate multiple independent computers within itself. Each VM has its own operating system (OS), virtual CPU, memory, and storage. This setup provides complete separation but is resource-intensive.
Unlike VMs, Docker containers share the hostβs operating system instead of running a full OS. Yet, they stay isolated from each other and the host using Linux features like namespaces (for separating processes and networks) and cgroups (for managing resources). This makes containers fast, lightweight, and secure, which is ideal for quick and consistent software deployment.
(image credit: this diagram was taken from Docker's website)
How is Docker used for delivery?
"Ok, but why do you use this? Why can't you just deploy your application directly?" Another solid question my dad raised with a frown.
In software engineering, we deploy applications to servers to make them accessible to users. A server is just another (usually powerful) computer, often hosted by cloud providers like AWS or Google Cloud. Deploying to a server involves copying your appβs code onto the machine and running it so that others can access your app.
You can deploy your app directly to a serverβbut thatβs like shipping loose cargo. If the serverβs environment is different from yours (like a different library version), your app might not work.
Docker lets you ship your app with its environment. So as long as the server supports Docker, your app runs exactly as it did on your computer.
Demo: How do you use Docker?
At this point, I wasnβt sure if my parents were impressedβ¦ or completely lost. Then my mom asked one last question: βSo how do you use Docker? It sounds complicated.β
Using Docker is actually pretty straightforward:
Install Docker Desktop on your computer.
In your appβs folder, create a file called a Dockerfile. In this file, you describe how to package your app β specifying the base system, required dependencies, and how to start the app.
This is a simple Dockerfile for a Node.js app:
# Use an official Node.js runtime as the base image
FROM node:18
# Create and set the working directory inside the container
WORKDIR /app
# Copy package.json and package-lock.json
COPY package.json ./
# Install dependencies
RUN npm install
# Copy the rest of your application code
COPY . .
# Expose the port your app runs on
EXPOSE 3000
# Command to run your app
CMD ["node", "index.js"]
- Build a Docker image:
docker build -t my-app .
This command creates a Docker image. Itβs not a picture but a set of files that contains everything needed to run your app (like a blueprint for creating the container). These files are stored inside Dockerβs internal storage area.
- Run the container:
docker run my-app
This command starts a container, which is a running instance of the image you built in the previous step.
Your app is now running inside a container!
Hope this guide was helpful! Let me know in the comments what you thought of it and if you have any questions π
Top comments (1)