What Is Docker and Do Beginners Need It?
Docker is a tool that packages your application along with everything it needs to run (operating system libraries, language runtimes, dependencies) into a single unit called a container. This container runs identically on your laptop, your teammate's laptop, and the production server. Beginners do not need Docker right away. Start with it when you hit "it works on my machine" problems or when a job requires it.
The problem Docker solves
You build a Node.js app on your MacBook. It works perfectly. You send the code to your teammate who runs Ubuntu. Their app crashes because they have Node 18 and you have Node 20. You deploy to a server. It crashes again because a system library is missing.
"It works on my machine" is one of the most common frustrations in software development. The root cause is that your app depends on things outside your code: the Node.js version, the operating system, installed libraries, environment variables, and file paths.
Docker solves this by packaging your app with all its dependencies into a container. The container carries everything it needs, so it runs the same everywhere.
How Docker works: images and containers
Two core concepts:
An image is a blueprint. It is a read-only template that defines what goes into the container: the base OS, the Node.js runtime, your code, your npm packages, and how to start the app.
A container is a running instance of an image. You can run multiple containers from the same image, just like you can print multiple copies of a document from the same PDF.
You define an image using a Dockerfile:
# Dockerfile
# Start with the official Node.js 20 image
FROM node:20-alpine
# Set the working directory inside the container
WORKDIR /app
# Copy package files and install dependencies
COPY package.json package-lock.json ./
RUN npm ci
# Copy the rest of the application code
COPY . .
# Build the app
RUN npm run build
# Tell Docker which port the app uses
EXPOSE 3000
# Start the app
CMD ["npm", "start"]Build the image and run it:
# Build the image (the -t flag names it)
docker build -t my-app .
# Run a container from the image
docker run -p 3000:3000 my-appYour app is now running inside a container. Open http://localhost:3000 and it works, regardless of what is installed on the host machine.
Docker containers vs virtual machines
A virtual machine (VM) runs a full operating system on top of your OS. It is like running Windows inside macOS. A VM is heavy: it needs its own kernel, its own file system, and gigabytes of RAM.
A Docker container shares the host's kernel. It only packages the application layer: your code, libraries, and runtime. This makes containers:
- Faster to start: A container starts in seconds. A VM takes minutes.
- Smaller: A Node.js container image is 100 to 200 MB. A VM image with a full OS can be several GB.
- More efficient: You can run dozens of containers on a single machine. Running dozens of VMs would require serious hardware.
Containers are not a replacement for VMs in every scenario. VMs provide stronger isolation and can run different operating systems. But for most web application development, containers are the better choice.
The honest answer: do beginners need Docker?
Not right away. Here is why:
If you are learning to build web apps with Next.js, React, or Express, Docker adds complexity without solving a problem you have yet. You are the only developer. You have one laptop. Deploying to Vercel or Railway does not require Docker. Focus on building things first.
Start using Docker when:
- You join a team and the project uses Docker for local development.
- Your app needs a database (PostgreSQL, Redis) locally, and installing them natively is painful.
docker compose upspins them up in seconds. - You are deploying to a platform that expects containers (AWS ECS, Google Cloud Run, DigitalOcean).
- You have environment-specific bugs: "it works on my machine but not on the server."
- A job posting lists Docker as a requirement.
You can skip Docker for now if:
- You deploy to Vercel, Netlify, or Railway (they handle containers for you).
- You are using managed databases like Supabase or PlanetScale.
- You are the only developer on the project.
Docker Compose: running multiple services together
Most real apps need more than one service: a web server, a database, maybe a Redis cache. Docker Compose lets you define and run them together.
# docker-compose.yml
services:
app:
build: .
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgresql://postgres:password@db:5432/myapp
depends_on:
- db
db:
image: postgres:16-alpine
ports:
- "5432:5432"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- POSTGRES_DB=myapp
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:One command starts everything:
docker compose up
# Both your app and PostgreSQL start together
# Your app can connect to the database at db:5432This is where Docker becomes genuinely useful for beginners: spinning up a local database without installing PostgreSQL natively. No version conflicts, no permission issues, no leftover data when you are done.
# Stop everything and clean up
docker compose downEssential Docker commands
If you decide to start with Docker, these are the commands you will use daily:
# Build an image from a Dockerfile
docker build -t my-app .
# Run a container
docker run -p 3000:3000 my-app
# Run in the background (detached)
docker run -d -p 3000:3000 my-app
# List running containers
docker ps
# Stop a container
docker stop container_id
# See logs from a container
docker logs container_id
# Open a shell inside a running container
docker exec -it container_id sh
# Remove all stopped containers and unused images (clean up disk space)
docker system pruneDocker images can eat up disk space quickly. Run docker system prune periodically to clean up old images and stopped containers.
Frequently Asked Questions
- Do I need Docker to deploy to Vercel?
- No. Vercel builds and runs your Next.js app without Docker. Vercel, Netlify, and similar platforms handle the container layer for you. Docker is useful when deploying to platforms like AWS ECS, Google Cloud Run, or a VPS where you manage the server yourself.
- Is Docker only for backend developers?
- Primarily, yes. Frontend developers rarely need Docker directly because frontend apps are static files served by a CDN. However, full-stack developers who need a local database or who work on teams with Docker-based development environments will encounter it regularly.
- How much memory does Docker use?
- Docker itself is lightweight, but each container uses whatever memory its application needs. A Node.js container might use 100 to 300 MB. A PostgreSQL container uses about 50 to 100 MB. On a machine with 8 GB of RAM, you can comfortably run several containers for local development.
Ready to build real-world apps?
Join the McTaba Labs full-stack marathon. Ship 8 production apps with M-Pesa, USSD, and WhatsApp integrations, and get career support until placement.
See Programs