Skip to content
Home/Resources/Software Development/Docker for beginners
Concept ยท Software Development

Docker for beginners: what it is, the commands and a Dockerfile

Younus FardeenBy Younus FardeenUpdated 1 Dec 20268 min read
Short answer

Docker packages an app and everything it needs into an image, and runs that image as an isolated process called a container. Unlike a virtual machine, containers share the host's kernel, so they start in about a second and are small. You describe the image in a Dockerfile and run it with docker run.

On this pageDocker vs a virtual machineImage vs container vs volumeA Dockerfile for a small Python app, line by lineThe Docker commands you will actually typeDocker Desktop licence: what the current terms sayFrequently asked questions

This page is for students who keep hearing "just use Docker" and want the model first, then the five commands that do most of the work. We read the official Docker documentation on 1 December 2026 and checked every command against its reference page. We did not run them: Docker is not installed on the machine used to write this, so no terminal output is shown and none is invented. The Python app below was run directly with python3 and answered a request on port 8000.

Docker is usually the step after you have a working app and before you deploy it. For where it fits, see the DevOps engineer roadmap and DevOps project ideas.

  1. 1Dockerfilerecipe: base image, files, command
  2. 2Imagebuilt, read-only package from the recipe
  3. 3Containera running process started from the image
  4. 4RegistryDocker Hub or similar, where images are shared
How the four Docker pieces connect.

Docker vs a virtual machine

Docker runs apps in containers, and a container is, in Docker's own words, an ordinary process that runs in isolation with its own filesystem, its own view of processes and network, and limits you can set. A virtual machine instead boots a whole guest operating system with its own kernel. The comparison comes from Docker's What is a container? guide, verified by Docker on 21 October 2026.

ContainerVirtual machine
What it isAn isolated process on the hostA full simulated computer
Operating systemShares the host kernel; carries only the app's filesBoots its own guest OS and kernel
Start timeAbout a second, per Docker's guideLonger: an OS must boot
IsolationStrong, but separated by a shared kernelStronger: separated by a hardware boundary
Typical sizeSmaller, since there is no guest OSLarger
Common useOne container per app part: backend, databaseCloud servers, strong tenant separation

The two combine in practice. Cloud servers are usually VMs that run many containers, and on macOS and Windows Docker Desktop runs your Linux containers inside a small Linux VM it manages, because Linux containers need a Linux kernel to share.

Image vs container vs volume

Beginners mix these three up because the commands look alike. An image is the recipe's finished output; a container is an image that is running; a volume is data that survives the container.

TermIs it running?What it holdsAnalogyKey commands
DockerfileNo, it is a text fileBuild instructionsA recipedocker build
ImageNo, it is immutableOS files, runtime, dependencies, your code, the start commandA frozen mealdocker pull, docker images, docker image rm
ContainerYes, or stoppedA live process plus a thin writable layerThe meal being eatendocker run, docker ps, docker stop, docker rm
VolumeNot applicableData that must outlive a containerAn external drivedocker volume create, docker run -v
RegistryNot applicableStored images with tagsAn app storedocker pull, docker push

The point about volumes is the one that costs people data: Docker's guide on persisting container data says a container keeps the files it writes inside itself, and removing the container removes them. Put database files in a named volume (-v mydata:/var/lib/data) or a bind mount of a folder on your disk.

A Dockerfile for a small Python app, line by line

A tiny web server, using only the standard library so there is nothing to install. We ran it with python3 app.py and a request to http://localhost:8000 returned Hello from a container. APP_ENV=unset.

# app.py
import os
from http.server import BaseHTTPRequestHandler, HTTPServer

class Hello(BaseHTTPRequestHandler):
    def do_GET(self):
        body = f"Hello from a container. APP_ENV={os.getenv('APP_ENV', 'unset')}\n".encode()
        self.send_response(200)
        self.send_header("Content-Length", str(len(body)))
        self.end_headers()
        self.wfile.write(body)

if __name__ == "__main__":
    # 0.0.0.0, not 127.0.0.1: inside a container, localhost is the container only
    HTTPServer(("0.0.0.0", 8000), Hello).serve_forever()

The Dockerfile. We proofread it against the Dockerfile reference and confirmed the base tag python:3.12-slim exists on Docker Hub (last pushed 28 November 2026). We did not build it.

# Dockerfile
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["python", "app.py"]
  • FROM python:3.12-slim picks the base image: Python on a minimal Debian. Pin a tag like this, not latest, so builds stay repeatable.
  • WORKDIR /app sets the folder inside the image for the following commands.
  • COPY requirements.txt . then RUN pip install ... come before copying your code. Docker caches each step as a layer, so dependencies are reinstalled only when requirements.txt changes. This demo app has no packages, so create an empty requirements.txt; a real app lists them there.
  • COPY . . brings in the rest of the code. Add the .dockerignore file below so secrets and junk stay out.
  • EXPOSE 8000 documents the port the app listens on. It does not publish it; -p does that at run time.
  • CMD ["python", "app.py"] is the exec form (a JSON array), which the reference recommends for ENTRYPOINT and works well for CMD.
# .dockerignore
.git
.env
__pycache__/
.venv/
node_modules/

The most common beginner failure is binding the server to 127.0.0.1. Inside a container that address means only the container, so the published port gives you an empty reply. Bind to 0.0.0.0, as in app.py. Next steps once this works: add a non-root USER (documented in the Dockerfile reference) and a multi-stage build.

The Docker commands you will actually type

Each command below has a page in Docker's CLI reference. The flags shown were checked there: -d runs in the background, -p publishes a port as hostPort:containerPort, -e sets an environment variable, -v mounts a volume, --rm removes the container when it exits, --name names it.

CommandWhat it does
docker build -t hello-app .Builds an image from the Dockerfile in this folder and tags it
docker run --rm -d --name hello -p 8000:8000 hello-appStarts a container in the background, port 8000 on your machine to 8000 inside
docker ps and docker ps -aLists running containers, then all containers including stopped ones
docker logs helloPrints what the container wrote to stdout and stderr
docker exec -it hello shOpens a shell inside a running container for debugging
docker stop hello and docker rm helloStops a container, then deletes it
docker images and docker image rm <image>Lists local images, then deletes one
docker pull <image>Downloads an image from a registry
docker volume create mydataCreates a named volume
docker compose upStarts all services defined in a compose.yaml: app plus database in one command

A full cycle for the demo app, to run once Docker is installed:

docker build -t hello-app .
docker run --rm -d --name hello -p 8000:8000 -e APP_ENV=dev hello-app
curl http://localhost:8000
docker logs hello
docker stop hello

When you have several containers, such as an app and a database, move to Compose. Everything above is deployed for free in free hosting for AI-built apps, and the pipeline that builds an image on every push is covered in CI/CD pipeline explained.

Docker Desktop licence: what the current terms say

Docker Desktop, the app for Windows, macOS and Linux, is not the same thing as the open-source Docker Engine. As of 1 December 2026, Docker's licence page says Docker Desktop is licensed under the Docker Subscription Service Agreement and is free for personal use, education, non-commercial open source projects, and small businesses (fewer than 250 employees and less than $10 million in annual revenue). It requires a paid subscription for professional use in larger organisations and for government entities.

Docker's page also states that the licensing of Docker Engine and the Moby open-source projects is not changing. So a student learning at home or in college is in the free category, while a larger company's employees need their employer to hold a subscription. Terms change: the agreement shows a last-updated date of 26 August 2026 as read on 1 December 2026. This is a summary of a public page, not legal advice; read the current terms before relying on it at work.

Frequently asked questions

What is Docker in simple terms?

Docker is a tool that packs an app with everything it needs, such as the language runtime and libraries, into an image. You run that image as a container, an isolated process, and it behaves the same on your laptop, a teammate's machine and a server. It removes the "works on my machine" problem.

What is the difference between a Docker image and a container?

An image is a read-only package: files, dependencies and a start command. A container is a running instance of an image, with a thin writable layer on top. You can start many containers from one image, and deleting a container does not delete the image.

Is Docker the same as a virtual machine?

No. A virtual machine boots a full guest operating system with its own kernel. A container is a process that shares the host's kernel, so it is smaller and starts in about a second. VMs isolate more strongly. Cloud servers often run containers inside VMs, so the two are used together.

Is Docker free for students?

Docker's licence page, read on 1 December 2026, lists personal use and education as free for Docker Desktop, and non-commercial open source as free too. Larger companies need a paid subscription for professional use. Docker Engine, the open-source part, has its own licence that Docker says is not changing.

How do I stop losing data when a container is deleted?

Data written inside a container is removed with it. Store anything you care about in a named volume (docker volume create, then -v name:/path) or a bind mount of a folder on your disk, so the data lives outside the container and survives replacement.

What is the difference between CMD and RUN in a Dockerfile?

RUN executes during the image build, for example installing packages, and its result is saved in the image. CMD sets the default command that runs when a container starts from the image. A Dockerfile can have many RUN lines but only the last CMD takes effect.

Learn this with mentors

Programmes for builders and engineers with admissions open: live classes, mentors and project work.

Continue learning

Roadmap

DevOps engineer roadmap

Linux, CI/CD, Docker, Kubernetes, cloud and monitoring in eight stages

6 min read
Concept

CI/CD pipeline explained

Stages, a working GitHub Actions workflow and rolling, blue-green, canary

7 min read
Concept

Microservices vs monolith

A decision table, the modular monolith default and the cost of distribution

7 min read