Short answer: Docker runs a program in a container, an isolated process started from an image that already holds the program and everything it needs. On a Linux VPS you learn the basics in five steps: run hello-world, run nginx with a published port, serve your own files from a bind mount, build your own image from a Dockerfile, and connect containers over a network.
docker run hello-world # 1. first container
docker run -d --name web -p 8080:80 nginx:1.30 # 2. a web server on port 8080
docker rm -f web
docker run -d --name web -p 8080:80 \
-v "$PWD/site":/usr/share/nginx/html:ro nginx:1.30 # 3. your own files
docker build -t my-site:1.0 . # 4. your own image
docker network create appnet # 5. a network for several containersDocker has to be installed first; the steps for Ubuntu, Debian and Rocky Linux are in how to install Docker on Ubuntu and Debian, and this tutorial starts where that one ends. Put sudo in front of each command unless your user is in the docker group. Docker was not run for this article: the commands and output follow the getting started guide on docs.docker.com and the official hello-world and nginx pages on Docker Hub, read on 11 November 2026.
Why use Docker, and when not to
Docker’s own overview names three reasons: fast, consistent delivery (the image you tested is the image you deploy, which suits CI/CD pipelines), portable workloads that run the same on a laptop, a VPS or a cloud host, and more workloads on the same hardware than with one virtual machine per service. In daily server work that turns into these use cases:
- Self-hosted apps. Most open source web apps ship an official image, so running n8n or a chat front end for Ollama is a
docker runinstead of a page of install steps. - Several versions side by side. Two apps that need different PostgreSQL or Node.js versions each get their own container, and the host stays clean.
- Repeatable deploys and rollbacks. As long as you never reuse an image tag such as
my-site:1.0for a new build, it stays on one exact image, and going back means starting the previous tag. - Trying software safely.
docker rmremoves the experiment completely, without leftovers in/etcor/usr.
Skip it when one program from your distribution’s packages does the job, for example a single static site served by nginx installed with apt. Docker adds a layer to learn and to update, and it changes the firewall: published container ports are forwarded before ufw’s rules see them, as the install guide explains.
Docker concepts: images, containers, volumes, ports and networks
| Term | What it is | Command you will use |
|---|---|---|
| Image | A read-only template with the program, its files and its default command | docker pull nginx:1.30 |
| Container | A runnable instance of an image, with its own writable layer | docker run, docker ps -a |
| Registry | A server that stores images; Docker Hub (docker.io) is the default | docker pull, docker push |
| Volume | Storage managed by Docker that outlives the container | -v mydata:/data |
| Bind mount | A host folder or file made visible inside the container | -v /srv/site:/usr/share/nginx/html |
| Published port | A host port forwarded to a port inside the container | -p 8080:80 |
| Network | A virtual network; on a user-defined one, containers find each other by name | docker network create appnet |
| Dockerfile | A text file with the instructions to build an image | docker build -t my-site:1.0 . |
The first two are the ones beginners mix up. An image is to a container what a program file is to a running process: one image can start many containers. Docker image vs container goes deeper into layers, storage and the lifecycle of each.
Step 1: docker run hello-world
docker run hello-worldThe image is not on the server yet, so Docker downloads it from Docker Hub first, then starts a container that prints a message and exits. The message explains exactly what happened:
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.The docker command is only a client; the work is done by the daemon, dockerd. The container has stopped but still exists: docker ps lists running containers, docker ps -a shows the stopped one too, with an automatic name. Add --rm to a docker run that you only need once and Docker removes the container when it exits.
Step 2: run nginx and publish a port
docker run -d --name web -p 8080:80 nginx:1.30
docker ps
curl -I http://127.0.0.1:8080
docker logs web
docker stop web && docker rm web-druns the container in the background and--name webgives it a name you can use in later commands instead of its ID.-p 8080:80maps port 8080 on the host to port 80 in the container. The host side always comes first. Without-p, nginx runs but nothing outside Docker can reach it.nginx:1.30is image name and tag. Docker Hub listed 1.30 as the stable nginx line in November 2026. With no tag Docker useslatest, which moves to new releases, so pin a tag for anything that has to keep working.
curl should answer HTTP/1.1 200 OK, and docker logs web shows that request in nginx’s access log (the official image links that log to the container’s output). The docker run options you will use most, from environment variables to restart policies, are in the docker run command guide.
Step 3: serve your own files with a bind mount
mkdir -p ~/docker-demo/site && cd ~/docker-demo
echo '<h1>Hello from my container</h1>' > site/index.html
docker run -d --name web -p 8080:80 \
-v "$PWD/site":/usr/share/nginx/html:ro nginx:1.30
curl http://127.0.0.1:8080-v HOST_PATH:CONTAINER_PATH makes the host folder appear inside the container, here over the folder the nginx image serves from, /usr/share/nginx/html, and :ro makes it read-only for the container. Edit index.html on the host and the next request already shows the change, without a restart.
This is also where beginners lose data. Anything a container writes into its own filesystem lives in its writable layer, and Docker’s storage docs are blunt: that data “doesn’t persist when the container is destroyed.” Keep everything that matters in a bind mount or in a named volume, which Docker manages and keeps until you delete it. Databases normally use a volume; check the image’s Docker Hub page for the path, because it can change. The official postgres image, for example, moved it with version 18 to -v pgdata:/var/lib/postgresql.
Step 4: write a Dockerfile and build an image
A bind mount needs the files on the host. An image carries them inside, so the same thing runs on any server. In ~/docker-demo, create a file named Dockerfile:
FROM nginx:1.30
COPY site/ /usr/share/nginx/html/docker build -t my-site:1.0 .
docker image ls my-site
docker rm -f web
docker run -d --name web -p 8080:80 my-site:1.0-t my-site:1.0 names and tags the result, and the final . is the build context: the folder whose files COPY can see. A .dockerignore file in that folder keeps things such as .git or node_modules out of the context. The instructions you will meet in almost every Dockerfile:
FROMpicks the base image,WORKDIRsets the folder later steps work in,COPYbrings files in from the build context.RUNexecutes a command at build time, for example a package install;ENVsets an environment variable for the later build steps and for every container started from the image.EXPOSEdocuments the port the app listens on (it publishes nothing),USERswitches away from root, andCMDsets the default command.
Each change to site/ now needs a new build and a new tag, my-site:1.1. To run the image on another server, push it to a registry with docker push, or build it there from the same Dockerfile.
Step 5: connect containers with a network
A container started without --network joins the default bridge, where, in the words of Docker’s networking docs, containers “cannot refer to each other by name.” On a network you create, they can:
docker network create appnet
docker rm -f web
docker run -d --name web --network appnet my-site:1.0
docker run --rm --network appnet busybox wget -qO- http://webThe second container reaches the first as web, without any published port. That is how an app container talks to its database: both on one network, and only the front end published with -p.
Clean up what you created
docker rm -f web
docker rm $(docker ps -aq --filter ancestor=hello-world) # the stopped hello-world container
docker rmi my-site:1.0 nginx:1.30 hello-world busybox
docker network rm appnet
docker ps -adocker rm removes containers, docker rmi removes images, and an image cannot be removed while a container, even a stopped one, still uses it. Stopped containers, unused images and old build cache add up over time; removing Docker containers and images covers the prune commands and what each one deletes.
Where to go next: Compose and real apps
Once an app needs two or three containers with volumes and a network, typing docker run lines gets old. Docker Compose describes the services, networks and volumes in one YAML file and starts them with a single command; the Compose documentation on docs.docker.com has a quickstart.
For practice, a small Linux VPS is a good place to learn: unlike a laptop it has a public address, so you see right away what -p exposes and what 127.0.0.1 keeps private. Keep the Docker engine updated with the rest of the system, and pin image tags so an update is something you choose.
Frequently asked
What is Docker used for?
Docker packages a program with everything it needs into an image and runs it as an isolated container. It is used to deploy the same build from a laptop to a server, to run self-hosted apps from their official images, to keep different versions of a database or runtime apart on one host, and in CI pipelines.
What is the difference between a Docker image and a container?
An image is a read-only template: the files, settings and default command. A container is a running or stopped instance of that image with its own writable layer. One image can start many containers, and removing a container does not remove its image.
Why does my data disappear when I remove a Docker container?
Files a container writes to its own filesystem live in its writable layer, which is deleted with the container. Store anything that must survive in a named volume (-v mydata:/path) or a bind mount of a host folder (-v /srv/data:/path). Both stay when the container is removed.
Do I need Docker Compose to learn Docker?
No. Start with docker run, ports, volumes, a Dockerfile and a user-defined network, because Compose uses exactly those ideas. Compose becomes useful once an app needs several containers, since it describes them in one YAML file and starts them with one command.