How to Use Docker: The Beginner's Guide (First Container, First Image, and the Five Commands That Matter)
CodexFuse Team · 2026-10-28T19:52:20.417Z · 17 min read
Learning how to use Docker takes about an hour, and most of that hour is running real containers — not reading theory. Docker is a platform that packages an application and everything it needs into a container, a lightweight, isolated environment that runs the same way on your laptop, a teammate's machine, and a server. This Docker for beginners guide walks you through the whole first-use system in order: installing Docker, running your first container, serving a real website from a container, building your first image, and learning the five commands that matter — plus Docker Desktop versus Docker Engine, Docker Compose, and the mistakes that trip up every beginner.
One idea makes everything else click: an image is the snapshot, and a container is the running instance of that snapshot. You download or build an image once, and you can start, stop, and delete containers from it as often as you like without rebuilding anything. If you write your code in an editor first, start with our VS Code beginner guide — Docker runs your code, and VS Code is where you write it.
How do I use Docker for the first time?
To use Docker for the first time, install Docker Desktop (Windows or Mac) or Docker Engine (Linux), prove it works with docker run hello-world, then run a real web server with one docker run command and open it in your browser. That loop — install, verify, run something real — is the whole beginner system, and every section below is one step of it.
- Install Docker Desktop on Windows or Mac, or Docker Engine on Linux, from Docker's official install pages.
- Open a terminal and run
docker --versionto confirm the command works, thendocker run hello-worldto prove containers run. - Run a real web server with
docker run -d --name my-nginx -p 8080:80 nginx:alpineand openhttp://localhost:8080in your browser. - Check it with
docker ps, stop it withdocker stop my-nginx, and remove it withdocker rm my-nginx. - Build your first image from a two-line Dockerfile, run it, and then learn Docker Compose for multi-container apps.
What is Docker, and how is a container different from a virtual machine?
Docker is a platform for running applications inside containers, which are isolated environments that bundle an application's code, libraries, dependencies, and settings so it behaves the same wherever it runs. A container is not a small virtual machine: a virtual machine carries a full guest operating system, while a container shares the host system's kernel and isolates only the application and its dependencies. That shared kernel is why containers start in seconds and use far less memory than virtual machines — and also why their isolation is narrower than a VM's, a trade-off worth understanding before you trust a container with anything sensitive.
Three words carry the whole vocabulary. An image is a read-only snapshot: the packaged application plus its runtime and dependencies, stored as layers.
A container is a running instance of an image — you can start many containers from one image, and deleting a container does not delete the image. A Dockerfile is the text file of instructions that builds an image, and Docker Hub is the public registry where ready-made images live.
The practical payoff is the end of "it works on my machine." When your application runs inside a container, the environment travels with the code: the same image runs on your laptop, in testing, and in production. That consistency is why Docker became the default way to ship web applications, APIs, and the self-hosted tools developers run at home.
| Container | Virtual machine | |
|---|---|---|
| What it carries | App plus dependencies, on the shared host kernel | App plus a full guest operating system |
| Start time | Seconds | Minutes, while the guest OS boots |
| Size and memory | Small — one shared kernel, many containers | Large — a whole OS per machine |
| Isolation | Process-level isolation | Full machine-level isolation |
| Best for | Shipping apps consistently, running services side by side | Running a different OS entirely, or needing hardware-level isolation |
How do I install Docker on Windows, Mac, and Linux?
Install Docker Desktop on Windows or Mac and Docker Engine on Linux, always from Docker's official install pages — never from an unofficial download mirror. On Windows, Docker Desktop uses the WSL 2 backend; on Mac, pick the installer for your chip (Apple silicon or Intel); on Linux, install Docker Engine from Docker's own repository for your distribution. After installing, open a terminal and run docker --version — if it prints a version, the command line is talking to Docker correctly.
On Windows and Mac, Docker Desktop is the beginner's on-ramp because it bundles everything in one install: Docker Engine, the command line, Docker Compose, and a GUI dashboard for watching containers. On Linux you have a choice: Docker Engine alone gives you the engine and the command line with no GUI, while Docker Desktop for Linux adds the dashboard on top. Beginners on Linux should start with Engine alone unless they specifically want the dashboard — the command line is where the learning happens either way.
Check the license before you install on a work machine. Docker Desktop is free for personal use, education, non-commercial open source projects, and small businesses with fewer than 250 employees and less than $10 million in annual revenue — both conditions must hold — and it requires a paid subscription (Pro, Team, or Business) for professional use in larger organizations and for government entities, according to Docker's own license page, updated September 28, 2026. The engine itself is open source and is not covered by that subscription, which is why Linux servers run Docker Engine with no license question at all.
How do I run my first container?
Run docker run hello-world in your terminal: Docker downloads the tiny official test image if you do not have it yet, creates a container from it, starts it, prints a confirmation message, and exits. Beginners often think nothing happened, because the container exits immediately — but that is exactly the point: the hello-world container's only job is to print a message and stop, so a clean exit with a confirmation message means Docker works.
After it exits, run docker ps -a to see it. docker ps alone lists only running containers, so a finished hello-world container is invisible there; the -a flag shows all containers, including stopped ones. Reading that list is a skill in itself, so learn its columns now: the container ID, the image it came from, the command it ran, when it was created, its status, its port mappings, and its name.
| docker ps column | What it tells you |
|---|---|
| CONTAINER ID | The short ID of the container — usable in place of its name in most commands |
| IMAGE | The image this container was started from |
| STATUS | Whether it is up, and for how long, or when it exited |
| PORTS | Which host ports map to which container ports |
| NAMES | The readable name, either one you set with --name or one Docker generated |
How do I run a real website with Docker?
Run a real website with one command: docker run -d --name my-nginx -p 8080:80 nginx:alpine, then open http://localhost:8080 in your browser to see the nginx welcome page. This is the moment Docker stops being abstract: a web server you never installed is answering on your own machine, inside a container, and your machine's nginx-free state has not changed at all.
Each flag earns its place. -d runs the container in the background (detached mode), so your terminal stays free. --name my-nginx gives the container a readable name you can use in later commands instead of a random one.
-p 8080:80 maps port 8080 on your machine to port 80 inside the container, which is the port nginx listens on — the order is host first, container second, and mixing them up is the most common beginner error. nginx:alpine is the image name and tag: the official nginx image built on tiny Alpine Linux.
Once it runs, practice the inspection commands on it. docker logs my-nginx shows the server's log output, which is where you look first when a container misbehaves. docker stop my-nginx stops it gracefully, and docker rm my-nginx deletes the stopped container — deleting the container does not delete the image, so you can start it again any time with the same docker run command.
If you want a full site rather than a welcome page, the same pattern runs WordPress in a container too — our WordPress beginner guide covers building the site itself, and Docker is how you run it identically anywhere.
How do I build my first Docker image?
Build your first image by writing a two-line Dockerfile that starts from nginx and swaps in your own page, then running docker build -t my-first-image . in the same folder. The Dockerfile is the recipe: FROM nginx:alpine says which image to start from, and COPY index.html /usr/share/nginx/html/index.html says to replace nginx's default page with yours. Create an index.html file next to the Dockerfile with a heading like "Hello from my Docker container!" and you have a complete project.
Build it, then run it on a different port so it does not clash with the first container: docker run -d --name custom-nginx -p 8081:80 my-first-image, then open http://localhost:8081 to see your own page served by a container. The -t my-first-image flag tags the image with a name you choose, and the trailing . tells Docker to use the current folder as the build context — the set of files it is allowed to copy into the image.
Two habits keep builds fast and safe from the start. First, each Dockerfile instruction adds a layer, and Docker caches layers, so a rebuild after a small change only repeats the steps after the first changed line — put the lines that change rarely (like installing dependencies) before the lines that change often (like copying your code). Second, add a .dockerignore file next to the Dockerfile listing folders Docker should never send as build context, such as .git — it keeps builds fast and keeps secrets out of your images. Keep your code itself under version control as usual: our GitHub beginner guide covers the repository habits that pair with this workflow.
What are the five Docker commands that matter most?
The five Docker commands that matter most are build, run, ps, stop, and pull — they cover the entire beginner loop of making images, starting containers, checking them, stopping them, and fetching images. Learn these five cold, and every other command is a variation: logs for reading output, rm for deleting stopped containers, exec for opening a shell inside a running container, and images for listing what you have downloaded.
| Command | What it does | Beginner example |
|---|---|---|
| docker pull | Downloads an image from a registry without starting it | docker pull nginx:alpine |
| docker build | Builds an image from a Dockerfile in the current folder | docker build -t my-first-image . |
| docker run | Creates a container from an image and starts it | docker run -d -p 8080:80 nginx:alpine |
| docker ps | Lists running containers; add -a to include stopped ones | docker ps -a |
| docker stop | Stops a running container gracefully | docker stop my-nginx |
A useful memory aid: pull fetches, build makes, run starts, ps checks, stop ends. When something goes wrong, add docker logs <name> to read what the container actually said, and docker inspect <name> to see its full configuration — those two commands solve most beginner mysteries before any forum post can.
What is Docker Desktop, and how is it different from Docker Engine?
Docker Desktop is the all-in-one application for Windows and Mac (and optionally Linux) that bundles Docker Engine, the command line, Docker Compose, and a GUI dashboard; Docker Engine is the underlying open source runtime that actually runs containers. On Linux, the engine runs directly on your system, so you can install Engine alone and skip Desktop entirely. On Mac and Windows, containers need a Linux environment to run in, and Docker Desktop provides that environment invisibly — which is why Desktop is the only official route on those systems.
The dashboard is the part most guides skip, and it is the beginner's actual on-ramp on Windows and Mac. It shows your containers, images, and volumes in a window, lets you start, stop, and delete containers with clicks, and shows each container's logs without a terminal command. Use the dashboard to learn what is running, and use the terminal to learn the commands — the two reinforce each other, and neither replaces the other.
Do not confuse the two licenses. Docker Desktop is covered by the Docker Subscription Service Agreement, with the free-versus-paid line described in the install section above; Docker Engine and the open source Moby project behind it are not changing their licensing, and Engine installed on its own from a Linux repository carries no subscription question. If you are near the small-business thresholds at work, read the agreement itself rather than a summary — the thresholds apply to the whole organization, not to your team.
What is Docker Compose, and when should a beginner use it?
Docker Compose is the tool for running several containers as one application, defined in a single compose.yaml file instead of a string of docker run commands. Use it the moment your app needs more than one piece — a website plus a database is the classic case — because one file then documents the whole setup, and a teammate can reproduce it with a single command.
A minimal Compose file for the nginx example looks like this:services: web: image: nginx ports: - "8080:80"
Save that as compose.yaml in a project folder, then run docker compose up -d to start everything in the background and docker compose down to stop and remove what it created. Compose is not a replacement for learning docker run — it is what you graduate to once typing the same flags for the third container gets old, and it is the file format real projects actually share.
What mistakes do Docker beginners make most?
The most expensive beginner mistake is storing important data only inside a container: containers are meant to be disposable, and deleting a container can delete the data that lived only in it. Use Docker volumes for anything you need to keep — databases especially — because volumes survive container deletion unless you remove them deliberately. Treat a container like a process, not a filing cabinet.
The next three mistakes are all small and all common. Using the latest tag without thinking means your next pull can silently change versions, so pin a version tag (like nginx:alpine) once a setup works. Mapping ports in the wrong order (-p 80:8080 instead of -p 8080:80) produces a server that looks dead, so read the flag as host-then-container every time.
And running images from untrusted sources is like installing software from strangers: prefer official or verified images on Docker Hub, especially for databases, web servers, and languages, and keep images updated.
Finally, do not paste commands you do not understand into a terminal that can reach your files. Docker commands can mount your folders into containers and delete containers and images in bulk, so read each flag before you press Enter — the five commands in this guide are all you need for your first week, and anything beyond them can wait until you know what it does.
What should I learn after my first container?
After your first container, learn volumes, networks, and Compose in that order, then pick a real project to containerize — a personal website, a self-hosted tool, or a development environment you currently set up by hand. Volumes solve the data problem, networks explain how containers talk to each other, and Compose ties them together into a project you can share. Each topic builds directly on the five commands you already know.
Two natural next projects connect to the rest of this site's guides. If you automate work with AI tools, our Google Jules beginner guide covers an AI coding agent whose work you will want to run in reproducible environments — exactly what containers are for. And when you are ready to run your containers somewhere other than your laptop, read what VPS hosting is: a VPS is the usual home for self-hosted containers, and the hosting decision matters as much as the container setup.
Sources
Docker Docs, "Docker Desktop license agreement" (updated September 28, 2026): Docker Desktop is free for small businesses (fewer than 250 employees and less than $10 million in annual revenue), personal use, education, and non-commercial open source projects, and requires a paid Pro, Team, or Business subscription for professional use in larger organizations and for government entities. https://docs.docker.com/subscription-billing/desktop-license/ — Docker Docs, "Install Docker Desktop on Windows": the install flow presents the Docker Subscription Service Agreement and confirms the same free and paid categories. https://Docs.Docker.com/desktop/setup/install/windows-install/ — Piyush Pandit, "Docker for Beginners: Build, Run, and Troubleshoot Your First Container" (DEV, October 27, 2026): the nginx run command with -d, --name, and -p flags, docker ps and ps -a, the FROM nginx:alpine plus COPY Dockerfile, docker build -t, docker logs, docker inspect, docker stats, and stop/remove cleanup. https://dev.to/piyush_pandit_author/docker-for-beginners-build-run-and-troubleshoot-your-first-container-1ki9 — OnyxCode, "Docker for Beginners: Complete Guide 2026": the image-as-package versus container-as-running-app distinction, the container-versus-virtual-machine table including shared host kernel, and the Docker Desktop bundle of Engine, CLI, Compose, and GUI. https://onyxcode.dev/blog/docker-for-beginners-complete-guide/ — UMA Technology, "How to Install Docker on Windows 11 for Beginners": the compose.yaml nginx example with docker compose up -d and down, the warning that data stored only inside a container can be lost on deletion, the docker volume create example, and the advice to prefer official images. https://umatechnology.org/how-to-install-docker-on-windows-11-for-beginners/ — DevRun, "Is Docker Desktop free? Licensing and pricing in 2026" (checked October 14, 2026 against Docker's license and pricing pages): both free thresholds must hold, the thresholds apply to the whole organization, and the CLI, Engine, Buildx, and Compose underneath Desktop are open source. https://devrun.app/blog/is-docker-desktop-free
Frequently asked questions
Is Docker free?
Docker Engine is open source and free, and Docker Desktop is free for personal use, education, non-commercial open source projects, and small businesses with fewer than 250 employees and less than $10 million in annual revenue. Larger organizations and government entities need a paid Pro, Team, or Business subscription for Desktop — check Docker's license page at install time, since terms can change.
Is a Docker container a virtual machine?
No. A virtual machine runs a full guest operating system, while a container shares the host system's kernel and isolates only the application and its dependencies. Containers are therefore much lighter and faster to start, but their isolation is narrower than a VM's — which is why containers are ideal for shipping applications and VMs remain the choice when you need a whole separate machine.
Why did docker run hello-world exit immediately?
Because that is what the hello-world container is built to do: print a confirmation message and stop. A clean exit with the message means Docker works. Run docker ps -a afterwards to see the stopped container in the list — docker ps alone only shows containers that are still running.
What is the difference between Docker Desktop and Docker Engine?
Docker Engine is the runtime that runs containers; Docker Desktop is the application that bundles Engine with the command line, Compose, and a GUI dashboard, plus the Linux environment containers need on Mac and Windows. On Linux you can run Engine alone, but on Mac and Windows, Desktop is the official route.
Do I need Docker Compose as a beginner?
Not on day one. Learn docker run first, then adopt Compose when your app needs more than one container — a website plus a database, for example. Compose replaces a string of run commands with one compose.yaml file that the whole project can share and reproduce with docker compose up -d.