Skip to main content
Techlogia — AI and Web Development Berlin

Practise this module for free on a real VM

Sign up for free
 All courses
Free to read – no sign-up

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.

Duration: 30 minLevel: BeginnerExercises: 4

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. 1. Check the Docker version

    Concept: the Docker CLI. With docker you control everything from the command line. First check that Docker is installed and reachable.

    docker --version > /tmp/docker-version.txt
    cat /tmp/docker-version.txt

    Check: /tmp/docker-version.txt starts with Docker version.

  2. 2. Run the hello-world container

    Concept: pull image & run container. sudo docker run hello-world automatically pulls the hello-world image (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 -a

    docker ps -a also shows finished containers — yours is listed with Exited (0).

    Check: sudo docker ps -a lists a container from the hello-world image with status Exited (0). The checker looks for itself.

  3. 3. nginx container with port mapping

    Concept: port mapping & detached. A web container is only useful if you can reach it. -p 8080:80 forwards host port 8080 to container port 80 (nginx). -d starts it in the background (detached), --name gives 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 -5

    Check: http://localhost:8080/ returns 200 OK and the nginx welcome page ("Welcome to nginx!"). The checker queries the port itself — the container has to be running.

  4. 4. Stop the container

    Concept: lifecycle — stop & list. sudo docker ps -a lists all containers (including stopped ones). docker stop cleanly ends a running container — but it stays around until you delete it with docker rm. Stop the nginx container and look at its status.

    sudo docker stop lab-nginx
    sudo docker ps -a

    Check: sudo docker ps -a shows lab-nginx with status Exited. 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 free

Lab content under CC BY 4.0 – free to use with attribution (© TechLogia).

How do you like this page?