"It works on my machine" is one of the oldest problems in software. An app runs on the developer's laptop, then fails on the test server because a library version is different or a setting is missing. Docker solves this by packaging the app together with everything it needs to run, so it behaves the same wherever it goes.
Start with two words that are easy to mix up. An image is a read-only template: your code, the runtime, the libraries and the start command, built in layers. A container is a running copy of an image. You build an image once and can start as many containers from it as you like, on your laptop, a server or a cloud platform.
Containers are not virtual machines. A virtual machine carries a whole operating system, so it is heavy and slow to start. A container shares the host's kernel and only carries what the app needs, so it starts in seconds and uses far less memory. That is why one server can run dozens of them.
An image is described in a Dockerfile, a short text file kept next to your code. A typical one picks a base image such as node:22-alpine, sets a working folder, copies the dependency file, installs the dependencies, copies the rest of the code and sets the command that starts the app. Each instruction becomes a layer, and Docker reuses unchanged layers on the next build, which is why dependencies are installed before the code is copied: changing your code does not force a full reinstall.
Four commands take you a long way. docker build -t myapp . builds an image from the Dockerfile in the current folder and names it myapp. docker run -p 8080:3000 myapp starts a container and maps port 3000 inside it to 8080 on your machine. docker ps lists the running containers, and docker logs followed by a container's name shows what it printed.
Containers are meant to be disposable, so anything you want to keep, such as a database's files, belongs in a volume that lives outside the container. Settings that change between environments, such as a database address, are passed in as environment variables rather than written into the image. And secrets never go into an image at all: anyone who can pull the image can read every file in it.
When an app needs more than one container, say a web app and a database, Docker Compose describes them together in a compose.yaml file and starts the whole set with docker compose up. It is the usual way to run a project's full stack on a laptop.
Once you can build and run images, you are ready for the next steps: pushing images to a registry such as Docker Hub, GitHub Container Registry or Azure Container Registry, building them automatically in a CI pipeline, and running them at scale with Kubernetes. All three are covered with hands-on labs in our DevOps course.





