Docker Essentials
2025-11-02 (4 min read)
Hey, if you're like me and have heard about Docker but aren't sure where to start, this post is for you. I'm gonna explain Docker in a way that actually makes sense. Let's just build something cool together.
What's Docker Anyway?
Think of Docker like this: You build a web app on your laptop. It works perfectly. Then you try to run it on a server, and boom – everything breaks. Different Node versions, missing packages, weird config issues.
Docker fixes that by packaging your whole app – code, dependencies, everything – into a little box called a container. Run that box anywhere, and it works the same. No more "works on my machine" excuses.
Getting Started
First, install Docker. Go to docker.com and grab Docker Desktop. It's free and works on Windows, Mac, or Linux.
Open your terminal and type:
docker --versionSee a version number? You're ready.
Your First Container
Let's try something fun. Run this:
docker run hello-worldDocker downloads a tiny test image and runs it. You should see a welcome message. Congrats! You just ran your first container.
Images vs Containers
Quick clarification:
- Image: The blueprint (like a recipe)
- Container: The running thing (like the actual cake)
You can make many containers from one image.
Running a Real Web Server
Let's run Nginx, a popular web server:
docker run -d -p 8080:80 nginx-dmeans detached (run in background)-p 8080:80maps your computer's port 8080 to the container's port 80
Go to http://localhost:8080 in your browser. Boom – web server running!
To stop it:
docker ps # find the container ID
docker stop <container-id>docker pslists all running containersdocker stopstops a container by its ID
Building Your Own Stuff
The real fun starts when you make your own images. You need a Dockerfile – it's like a recipe for your app.
Here's a simple one for a Node.js app:
Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]FROMspecifies the base image (Node.js on Alpine Linux)WORKDIRsets the working directory inside the containerCOPYcopies files from your computer to the containerRUNruns commands during the build (like installing packages)EXPOSEtells Docker which port your app listens onCMDspecifies the command to run when the container starts
package.json
{
"name": "my-app",
"scripts": { "start": "node app.js" },
"dependencies": { "express": "^4.18.0" }
}app.js
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("Hello from Docker!");
});
app.listen(3000, () => console.log("Running on 3000"));Build and run:
docker build -t my-app .
docker run -p 3000:3000 my-appdocker buildcreates your image-t my-apptags it with a name.means "use the current directory for the Dockerfile"docker runstarts your app in a container
Visit localhost:3000. Your app's running in a container!
Docker Compose for Bigger Projects
Got a full-stack app? Database + API + frontend? Docker Compose handles that.
Make a docker-compose.yml:
version: "3.8"
services:
api:
build: .
ports:
- "3000:3000"
db:
image: postgres:15
environment:
POSTGRES_PASSWORD: password
ports:
- "5432:5432"servicesdefines multiple containersapibuilds your Node appdbuses a Postgres image
Run everything with:
docker-compose upThat's it. Your whole stack starts together.
Quick Tips
- Use
.dockerignoreto skip files likenode_modules(just like.gitignore) - Keep images small – use
node:alpineinstead of full Node - Stop containers with
docker-compose down - Check logs with
docker logs <container-name>
That's the Basics
Docker takes practice, but start small. Containerize one of your projects first.
Got questions? The Docker docs are great. Or hit me up – I'm always happy to chat about this stuff.
follow on x.com for more updates