Practise this module for free on a real VM
Sign up for freeDocker Basics: your first container
You learn the building blocks of Docker on your lab VM: pulling images, running containers, port mapping, container lifecycle. Four tasks, all on your own VM — no external setup, no cloud account. At the end an nginx container runs behind port 8080 and you understand why docker is the default deploy tool for modern web apps.
From hello-world to a running web container
Docker basics: your first container
Docker is the standard tool today for packaging and shipping applications. A container is a lightweight, isolated unit that contains everything an application needs — and runs the same on any Docker host.
Key terms
- Image: an immutable template (e.g.
nginx,hello-world) from which containers are created. - Container: a running instance of an image.
- Port mapping (
-p): connects a container port to a host port, e.g.-p 8080:80. - Lifecycle: containers are started (
run), listed (ps), stopped (stop) and removed (rm).
Your goal
You check the Docker version, run the hello-world container, get an nginx container running behind port 8080, and stop it again — the full lifecycle. You note the Docker version in a file; after that the checker looks directly at what is really running on your server.
Exercises
1. Check the Docker version
Concept: the Docker CLI. With
dockeryou control everything from the command line. First check that Docker is installed and reachable.docker --version > /tmp/docker-version.txt cat /tmp/docker-version.txtCheck:
/tmp/docker-version.txtstarts withDocker version.2. Run the hello-world container
Concept: pull image & run container.
sudo docker run hello-worldautomatically pulls thehello-worldimage (if missing) and starts a container from it. It prints a confirmation message and exits — the "hello world" of the container world.sudo docker run hello-world sudo docker ps -adocker ps -aalso shows finished containers — yours is listed withExited (0).Check:
sudo docker ps -alists a container from thehello-worldimage with statusExited (0). The checker looks for itself.3. nginx container with port mapping
Concept: port mapping & detached. A web container is only useful if you can reach it.
-p 8080:80forwards host port 8080 to container port 80 (nginx).-dstarts it in the background (detached),--namegives it a name.Start an nginx container and check that it responds:
sudo docker run -d --name lab-nginx -p 8080:80 nginx curl -s http://localhost:8080/ | head -5Check:
http://localhost:8080/returns200 OKand the nginx welcome page ("Welcome to nginx!"). The checker queries the port itself — the container has to be running.4. Stop the container
Concept: lifecycle — stop & list.
sudo docker ps -alists all containers (including stopped ones).docker stopcleanly ends a running container — but it stays around until you delete it withdocker rm. Stop the nginx container and look at its status.sudo docker stop lab-nginx sudo docker ps -aCheck:
sudo docker ps -ashowslab-nginxwith statusExited. Do not delete it — the checker looks for the stopped container.
Knowledge check: your first container
No VM, about 3 minutes. You recall what the basic Docker commands do – wrong answers come back at the end.
Related courses
Now practice it yourself
Reading is good – doing is better. Practise this module on a real Linux VM, right in your browser. A free account is all it takes.
Start for freeLab content under CC BY 4.0 – free to use with attribution (© TechLogia).
