Linux & Docker · Lesson 5 of 7

Docker: images & containers

What containers solve, images vs containers, and running, inspecting and stopping containers.

“It works on my machine” happens when environments differ. Docker packages an app with its runtime and dependencies into an image, and runs it as an isolated container that behaves the same on every computer and server.

  • An image is a read-only template (like a class). A container is a running instance of it (like an object).
  • Images come from registries such as Docker Hub: docker pull nginx.
  • Containers share the host's kernel, so they start in seconds and are much lighter than virtual machines.
  • -p 8080:80 maps a port on your machine to a port in the container.

Example in the terminal

Run these on your own computer
$ docker run -d --name web -p 8080:80 nginx:alpine
Unable to find image 'nginx:alpine' locally
alpine: Pulling from library/nginx
Status: Downloaded newer image for nginx:alpine
3f1c2a9e7b61...

$ docker ps
CONTAINER ID  IMAGE         STATUS         PORTS                  NAMES
3f1c2a9e7b61  nginx:alpine  Up 8 seconds   0.0.0.0:8080->80/tcp   web

$ curl -s localhost:8080 | head -4
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>

$ docker logs web --tail 2
172.17.0.1 - - [10/Nov/2026:10:31:02 +0000] "GET / HTTP/1.1" 200 615

$ docker stop web && docker rm web
web
web

Lines starting with $ are commands you type; the rest is what the terminal prints. Use Linux, macOS, WSL on Windows or a free cloud shell. Names and paths are examples.

Key points

  • Containers package an app with everything it needs.
  • Image = template; container = running instance.
  • -p host:container publishes ports.
  • docker ps, logs, stop and rm manage containers.

Quick check

What does -p 8080:80 do?

Practice task

Run a container from the official httpd (Apache) image on port 8081, open it in your browser, read its logs, then stop and remove it.

Interview corner

What is the difference between a container and a virtual machine?

A VM runs a full guest operating system on a hypervisor, so it's heavy and slow to start. A container shares the host OS kernel and packages only the app and its dependencies, so it's lightweight and starts in seconds.

What is the difference between docker stop and docker rm?

docker stop shuts down a running container but keeps it (you can start it again). docker rm deletes a stopped container. docker rm -f does both.

Further reading

Official documentation, linked for deeper study. These are outside sites; this lesson's text is our own.

Original lesson written by the InfoparkDaily team · © 2026 InfoparkDaily · Free to learn — no paid course or subscription.