Docker 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. Write each output into the specified file.
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.
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.docker run hello-world > /tmp/docker-hello.txt cat /tmp/docker-hello.txtCheck:
/tmp/docker-hello.txtcontainsHello from Docker!.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:
docker run -d --name lab-nginx -p 8080:80 nginx curl -sI http://localhost:8080/ > /tmp/nginx-curl.txt cat /tmp/nginx-curl.txtCheck:
/tmp/nginx-curl.txtstarts withHTTP/1.1 200 OK.4. Stop the container
Concept: lifecycle — stop & list.
docker ps -alists all containers (including stopped ones).docker stopcleanly ends a running container. Stop the nginx container and document the status.docker stop lab-nginx docker ps -a > /tmp/docker-ps.txt cat /tmp/docker-ps.txtCheck:
/tmp/docker-ps.txtlists the containerlab-nginx(now stopped).
Now practice it yourself
Reading is good – doing is better. Start this course 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).
