Understanding Containers

October 7, 2025

What is a Container?

A container is a standard unit of software that packages code and all its dependencies so it runs consistently across computing environments.

-- Docker

Unlike virtual machines, which are slow to boot, containers start in seconds and are much more lightweight.

Virtual Machines vs Containers

Virtual machines (VMs) have been around for a long time. They run a full OS on top of your host machine using a hypervisor. Each VM has its own:

VMs work but are resource-heavy. Containers, on the other hand, share the host OS kernel, keeping apps isolated while being lightweight.

Advantages of Containers:

Images vs Containers

A container is basically a running instance of an image:

You can launch multiple containers from a single image. Think of it like a class (image) and objects (containers).

Pull Docker Image

Download the "nginx" image:

docker pull library/nginx

Check the images you have:

docker images

You can also see the image in Docker Desktop under the "Images" tab.

Run a Container

Start a container from an image:

# Example (don’t run exactly)
docker run -d -p hostport:containerport namespace/name:tag

Example:

docker run -d -p 3000:80 library/nginx:latest
docker ps

Visit http://localhost:3000 to see the running app.

Stop a Container

Two main ways to stop a container:

Example:

docker ps
docker stop CONTAINER_ID

Refreshing the webpage now should show the server is down.

Running Multiple Containers

Containers are lightweight. You can run many on the same host. Each container is isolated, even if multiple containers come from the same image.

Example: Start 2 instances of the "nginx" container on different ports:

docker run -d -p 3000:80 library/nginx
docker run -d -p 4000:80 library/nginx

Open each port in the browser to verify:

Use docker ps to see all running containers.

Key Takeaways