What is Docker? How to Build Your First Docker Image (Beginner Guide 2026)
Docker explained from scratch: what containers are, how to install Docker Desktop, and how to build and run your first Docker image — step by step with real commands. No prior experience needed.
Docker lets you package an application and everything it needs to run — code, runtime, libraries, settings — into a single portable unit called a container. That container runs the same way on any machine that has Docker installed.
This guide explains the core concepts, walks you through installing Docker, and gets you to a running container with your own Dockerfile.
What Docker is and how to build and run your first container from scratch.
Three concepts you need before anything else
Image — a read-only template that describes what your container will contain: the OS layer, the runtime (Node, Python, etc.), your code, and any configuration.
Container — a running instance of an image. Like a process that was spawned from the image blueprint.
Dockerfile — a text file with instructions that tell Docker how to build an image. Step by step: start from this base image, copy these files, install these packages, run this command.
The relationship:
snippet
Dockerfile → (build) → Image → (run) → Container
Step 1: Install Docker Desktop
Docker Desktop is the easiest way to get Docker running on your machine. It includes Docker engine, CLI, and a GUI dashboard.
-t my-docker-app — gives the image the name my-docker-app
. — tells Docker to look for the Dockerfile in the current directory
You'll see Docker execute each step. The first build takes a minute because it downloads the base image. Subsequent builds are much faster because Docker caches each layer.
Step 4: Run your container
bash
docker run -p 3000:3000 my-docker-app
-p 3000:3000 — maps port 3000 on your laptop to port 3000 inside the container
The previous command ran the container in your terminal window. To run it in the background:
bash
docker run -d -p 3000:3000 --name my-app my-docker-app
-d — detached mode (runs in the background)
--name my-app — gives the container a human-readable name
The container is running now without occupying your terminal. Check it:
bash
docker ps
This lists all running containers. You'll see my-app in the list.
Essential Docker commands
bash
# List running containers
docker ps
# List all containers (including stopped ones)
docker ps -a
# List all local images
docker images
# Stop a running container
docker stop my-app
# Start a stopped container
docker start my-app
# Remove a container
docker rm my-app
# Remove an image
docker rmi my-docker-app
# View container logs
docker logs my-app
# Follow logs in real time
docker logs -f my-app
# Run a command inside a running container
docker exec -it my-app sh
Step 6: Add a .dockerignore file
Just like .gitignore tells Git which files to ignore, .dockerignore tells Docker which files to exclude from the image build. This keeps images small and prevents accidentally copying secrets.