Sunday, 06 September 2026
Advertisement Advertise Your advert could be here Reach thousands of learners and ICT professionals across Rwanda. Contact us
Advertisement Opportunity Jobs, scholarships & hackathons Fresh openings from Rwandan job boards are pulled in every hour. See openings

Why containers exist

Docker and CI/CD · lesson 1 of 12

In this lesson: Explain what a container is and why it removes environment differences.

"It works on my machine" is not a joke about careless developers. It is an accurate description of a real problem: your laptop has PHP 8.2, the server has 8.1; you have ImageMagick installed, the server does not; your database is MySQL 8, production is MariaDB. The code is identical and the behaviour is not.

A container packages an application together with everything it needs to run — the runtime, the libraries, the system tools — into one artefact that behaves identically wherever it is started.

How it is different from a virtual machine

A virtual machine emulates a whole computer. It boots its own operating system kernel, which takes gigabytes of disk, hundreds of megabytes of memory and the better part of a minute.

A container does not. It shares the host's kernel and isolates only what the application sees: its own filesystem, its own process list, its own network. What remains is your application and its dependencies — tens of megabytes, started in under a second.

Virtual machineContainer
ContainsA full OS plus your appYour app plus its dependencies
SizeGigabytesTens to hundreds of megabytes
Start timeTens of secondsUnder a second
How many per serverA handfulDozens or hundreds
IsolationVery strong — separate kernelStrong, but the kernel is shared
The shared kernel is the trade. Containers are lighter because they do not each carry an operating system. The cost is that a kernel-level exploit escapes into the host. For running your own services this is fine; for running code you do not trust, the stronger isolation of a VM is still worth its weight.

The three words you need

TermWhat it is
ImageA read-only template: a filesystem plus instructions for what to run. Built once, never changed.
ContainerA running instance of an image. You can start twenty from one image.
RegistryA place images are stored and shared, like a Git remote but for images.

The relationship is the same as a class and its objects, or a recipe and the meals you cook from it. The image is the fixed thing; containers are disposable.

Immutability is the point

You do not log into a container and fix it. If something needs changing, you change the source, build a new image, and replace the container. This feels wasteful and is the single most valuable habit containers teach.

The alternative — servers you patch, tune and repair over years — produces machines nobody can rebuild. The configuration lives in the muscle memory of whoever set it up, and when that machine dies you discover you cannot recreate it. Containers make the build reproducible by making the running thing disposable.

Containers are not a security boundary you should lean on. They are a packaging and isolation tool. Running as root inside a container, mounting the Docker socket, or trusting an image you did not build are all ways to make the isolation meaningless. We will cover each.

The commands you will use constantly

docker ps                    # running containers
docker ps -a                 # including stopped ones
docker images                # images on this machine
docker logs -f my-app        # follow a container's output
docker exec -it my-app sh    # get a shell inside a running container
docker stop my-app
docker rm my-app
docker system df             # how much disk is Docker using?
docker system prune          # reclaim space from stopped containers and unused images
Docker will fill your disk. Old images, stopped containers and dangling build layers accumulate silently until a deploy fails with "no space left on device". Put docker system prune -af --volumes on a schedule, and read the flags before you run it on anything you care about.

Try it yourself

Run docker run --rm -it alpine sh. You are now inside a container. Run ls / — a complete Linux filesystem. Run ps aux — almost no processes, because you are seeing only this container's. Create a file, exit, and start the same command again: the file is gone, because you got a fresh container from an unchanged image. That is immutability in one minute.

Create a free account to save progress

All lessons in this track

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
    Networking and ports ~25 min account needed
  7. 7
  8. 8
  9. 9
    Making the pipeline deploy ~30 min account needed
  10. 10
    Infrastructure as code ~30 min account needed
  11. 11
    Releasing without downtime ~30 min account needed
  12. 12
Advertisement Yanjye Learn a new digital skill this week ICT, programming and professional courses with graded weekly assignments. Start free