techlogia — AI and Web Development Berlin
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. Write each output into the specified file.

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. 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.

    docker run hello-world > /tmp/docker-hello.txt
    cat /tmp/docker-hello.txt

    Check: /tmp/docker-hello.txt contains Hello from Docker!.

  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:

    docker run -d --name lab-nginx -p 8080:80 nginx
    curl -sI http://localhost:8080/ > /tmp/nginx-curl.txt
    cat /tmp/nginx-curl.txt

    Check: /tmp/nginx-curl.txt starts with HTTP/1.1 200 OK.

  4. 4. Stop the container

    Concept: lifecycle — stop & list. docker ps -a lists all containers (including stopped ones). docker stop cleanly 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.txt

    Check: /tmp/docker-ps.txt lists the container lab-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 free

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

Docker Basics: your first container