devops

Docker for Local Development: A Beginner’s Guide to Containers That Just Work

beginnerscontainersdevopsdockerlocal-development
Gerald VillorenteDecember 4, 20269 min read
Docker for Local Development: A Beginner’s Guide to Containers That Just Work

Imagine you could hand a friend your entire computer setup — every tool, every version, every setting — packed inside a small box they can open on any machine and have it work exactly the same. That box is Docker, and this guide will teach you how to use it.

We will start with the problem Docker solves, then build a simple mental picture using cars and factories that makes every strange Docker word click into place. After that you will install it, run your first app, write your own recipe, and connect a whole project together. No experience needed — if you can open a terminal window, you can follow along.

The problem Docker solves

Every new developer meets the same ghost: code that works perfectly on your laptop and breaks everywhere else. On your teammate's computer it crashes. On the server it crashes differently. You compare setups for hours and discover the tiniest differences — a newer database here, a missing tool there. Programmers even have a joke about it: it works on my machine.

Docker ends that joke. It lets you pack your entire application — the code, the tools, the database, the settings — into one sealed box that behaves exactly the same on every computer. If it runs in the box on your laptop, it runs in the box anywhere. This guide will take you from zero to confidently using that box in your daily work.

Think of your app like a car

The best way to understand Docker is a car factory. Keep this picture in your head and every strange word will click into place.

  • The Docker Engine is the factory floor and its machines. It is the program running on your computer that builds things and runs them. When people say Docker, they usually mean this engine plus its command line tools. (the engine)

  • An image is the blueprint plus all the parts on the shelf: the exact car design, every bolt, every drop of paint. A Docker image holds your code plus everything it needs to run: the language, the libraries, the settings. Images never change. You can copy them to any computer and they stay identical. (the blueprint)

  • A container is a finished car rolling off the line, engine running. It is a live copy made from an image. You can start ten identical containers from one image, drive each one differently, crash one on purpose, throw it away, and the blueprint stays untouched. (the running car)

  • A Dockerfile is the written recipe the factory follows: take this base, bolt on these parts, paint it this color. It is an ordinary text file, and you will write your first one in a few minutes. (the recipe)

Three more words complete the picture. A volume is the car's trunk: permanent storage bolted on, so your luggage (databases, uploaded files) survives even when you scrap the car. A network is the private road system letting your cars talk to each other. A port is a numbered door on the car: open one, and the outside world can reach a service inside.

Install it and take a first drive

Install Docker Desktop from the official site for your system (Windows, Mac, or Linux all work). It includes the engine and the command line tools. Open a terminal and prove it works:

docker run hello-world

That one line downloads a tiny blueprint, builds a car from it, starts it, watches it print a greeting, and parks it. Now try something with an engine that keeps running — a real web server:

docker run -d -p 8080:80 --name my-first-server nginx

Open your browser at localhost:8080 and you will see a welcome page. Here is what each piece meant: -d means drive in the background, -p 8080:80 connects door 8080 on your computer to door 80 inside the car, --name gives your car a nickname, and nginx names the blueprint to build from (Docker fetches it automatically from a public blueprint library called a registry).

  • docker ps shows your running cars.

  • docker logs my-first-server shows what its engine is saying.

  • docker stop my-first-server parks it. docker start my-first-server drives it again.

Write your first recipe: the Dockerfile

A Dockerfile is just a list of assembly steps, read top to bottom. Here is a complete one for a tiny Node.js app. You do not need Node installed — that is the whole point.

FROM node:20
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["node", "server.js"]
  • FROM node:20 — start from the official Node blueprint, so the tools arrive with the car.

  • WORKDIR /app — do all work inside a folder called /app.

  • COPY package*.json ./ — bring in the parts list first (this ordering trick lets Docker reuse earlier steps and build faster).

  • RUN npm install — bolt the parts on.

  • COPY . . — bring in your code last, since it changes most often.

  • CMD ["node", "server.js"] — the ignition key: what runs when the car starts.

Build your blueprint and drive it:

docker build -t my-app . — photograph each assembly step into a blueprint named my-app. The dot means look in this folder for the recipe. docker run -d -p 3000:3000 my-app — build a car from your blueprint and open its door.

Change your code, rebuild, and run again. Notice the rhythm: edit, build, drive. Each build only repeats the steps after your last change, so it gets faster as you go.

Running a whole garage: Docker Compose

Real apps are never one car. A typical project is at least two: your app plus a database, maybe a cache on the side. Starting each one by hand with long commands gets old fast. Compose lets you describe the whole garage in one small file called compose.yaml, then start everything with a single command.

A compose file lists services — one per car — each with its blueprint, doors, trunks, and roads. Your app service builds from your Dockerfile. A database service uses a ready-made blueprint like postgres. They share a private road automatically, so your app reaches the database simply by its service name, the way you would call a coworker by name across the office.

Two commands run your whole garage: docker compose up builds the blueprints (only the first time, or when recipes change) and starts every car, showing all their engines' output in one window. docker compose down parks everything. Add -d to run it quietly in the background, and docker compose logs -f to watch the engines talk.

Where does your stuff live? Volumes and bind mounts

Here is the one idea that confuses every beginner, so read slowly: containers forget. When you throw away a car, everything inside it goes with it — files your app saved, data your database stored, all gone. That is by design. Cars are disposable; luggage is not. So Docker gives you two kinds of trunks.

  • A volume is a trunk managed by Docker itself. You say store the database here, and Docker keeps it safe across rebuilds and restarts. This is where production data lives.

  • A bind mount is a window straight into a folder on your own computer. Your code folder appears inside the car, live. Save a file in your editor and the running app sees it instantly — no rebuild. This is the magic behind fast daily development.

In practice: bind-mount your code so edits appear instantly, and give your database a volume so your test data survives every restart. Lose the volume and you start Monday with an empty database — every beginner learns this once.

Doors and roads: ports and networks

The -p flag deserves its own minute because it trips everyone up. In -p 8080:80, the first number is a door on YOUR computer, the second is a door inside the car. Traffic knocking on your door 8080 gets forwarded to the car's door 80. Two cars can both listen on door 80 internally, as long as they open different doors on your computer — that is how you run five projects at once without collisions.

Networks are the private roads. Cars in the same garage talk to each other by service name with no extra setup. Nothing on those private roads is reachable from outside unless you deliberately open a door with -p. That isolation is a feature: your database has no public door at all, yet your app reaches it fine.

Your daily command cheat sheet

  • docker ps — which cars are driving right now.

  • docker logs <name> — read one car's engine output. Add -f to keep watching.

  • docker exec -it <name> sh — climb inside a running car and look around. Great for debugging.

  • docker compose up --build — rebuild blueprints and drive the whole garage.

  • docker compose down — park everything. Your volumes keep the luggage.

  • docker images — blueprints on your shelf. docker volume ls — trunks in storage.

Mistakes every beginner makes (so you do not have to)

  • Editing the Dockerfile and forgetting to rebuild. The running car still uses the old blueprint. Change the recipe, then rebuild.

  • Port already in use. Something else is parked in that door. Either stop it or pick a different outside door.

  • Copying everything including node_modules into the image. Add a .dockerignore file listing what stays out, the same way .gitignore works. Smaller blueprints build faster.

  • Running docker system prune on a shared machine without thinking. It throws away parked cars and unused blueprints — including other people's. Never run cleanup commands you cannot undo on computers you share.

  • Baking secrets into the blueprint. Passwords and keys do not belong in Dockerfiles or images, because anyone holding the blueprint can read them back out. Pass secrets at driving time through environment files instead.

  • Trusting the latest tag. Latest silently changes underneath you. When something must stay put, pin an exact version number.

Your first week in the garage

  1. Day one: install Docker and drive nginx and hello-world.

  2. Day two: write the tiny Node recipe above, build it, break it, fix it.

  3. Day three: add a database with compose and watch two cars talk.

  4. By Friday, develop with your code bind-mounted and your database on a volume — edit, save, refresh, repeat, with no installs on your own machine beyond Docker itself.

From then on, every project starts the same way: clone it, run one compose command, and you are driving the exact same setup as everyone else on the team. No more works on my machine. Just works.

Related reading

Read Logs Like a Detective: Finding the Clue in a Wall of Text
devops

Read Logs Like a Detective: Finding the Clue in a Wall of Text

December 2, 2026
beginnersdebuggingdevopslogging
Read →