We close Part IV with one of the most important topics in modern computing: containers. Before seeing how AWS manages them (ECR, ECS, EKS in the following subchapters), you need to understand what Docker and containers are. If you already know them, this will be a quick review; if not, here are the essentials.

The problem: “it works on my machine”

You’ve surely heard (or experienced) this classic phrase: a program works perfectly on the developer’s computer, but when moved to the server... it fails. Why? Because the server has a different version of the language, is missing a library, the operating system is different, a configuration doesn’t match... Environment differences break applications.

Developer’s computer                Production server
  Python 3.11                          Python 3.8        ← different!
  Library X version 2                  Library X version 1  ← different!
  Works ✓                              Fails ✗

The solution: containers

A container packages your application along with everything it needs to run: the code, libraries, dependencies, configuration... all in a single package. That package works the same anywhere: on your laptop, on the server, in the cloud. No more “it works on my machine.”

   ┌─── Container ───┐
   │  Your app        │
   │  + its libraries │   ← all together, self-contained
   │  + dependencies  │
   │  + configuration │
   └──────────────────┘
   Works the same ANYWHERE

Analogy: a container is like a shipping container (those on ships and trucks). It doesn’t matter what’s inside (clothes, electronics, food): the container has a standard size and shape, so any ship, crane, or truck in the world can transport it without knowing what’s inside. Same with software: the container is standard, and any system that “knows” about containers can run it.

What is Docker

Docker is the most popular technology for creating and running containers. It has become an industry standard. It handles three key concepts you should clearly distinguish:

  1. Image

An image is the template for the container: the “frozen” package with your application and everything it needs. It’s like a recipe or a mold. It doesn’t run by itself; it’s the definition of what will be inside.

  1. Container

A container is an image in execution: a live instance of the image, running. From a single image, you can launch many identical containers.

Image (template)  ──start──►  Container 1 (running)
                  ──start──►  Container 2 (running)
                  ──start──►  Container 3 (running)

Analogy: the image is like a cookie cutter (or a blueprint); the container is each cookie that comes out of the mold. One mold, many identical cookies.

  1. Dockerfile

A Dockerfile is a text file with the instructions to build the image. It describes step by step what it contains: which base system it starts from, what gets installed, what code is copied, how it starts. It’s the written recipe.

# Simplified Dockerfile example
FROM python:3.11              # starts from a base image with Python
COPY . /app                   # copies your code
RUN pip install -r requirements.txt   # installs dependencies
CMD ["python", "app.py"]      # how to start the application

From this Dockerfile, Docker builds the image, which you can then run as containers wherever you want.

The complete Docker flow

Bringing the three concepts together, the cycle is:

1. You write a Dockerfile  (the recipe)
        │ docker build
        ▼
2. You build an Image      (the ready package)
        │ docker run
        ▼
3. You start Containers    (the application running)

Containers vs virtual machines

You might wonder: how is a container different from an EC2 instance (virtual machine)? The key is that containers are lighter:

Virtual machine (EC2) Container
Includes A full operating system Only the app and its dependencies
Size Large (GB) Light (usually MB)
Startup Slow (minutes) Fast (seconds)
Density Few per server Many per server

Containers share the host server’s operating system, instead of each carrying a full one. That’s why they’re so light and fast: you can run many containers on a single machine.

Why this matters in AWS: containers are ideal for the cloud. They start quickly (great for scaling, Chapter 13), are portable, and make good use of resources. That’s why AWS has dedicated services to run them, which we’ll see in the next subchapters: ECR (to store images), ECS and EKS (to run containers).

What you should remember

  • A container packages your application with everything it needs (code, libraries, dependencies, configuration), and works the same anywhere. It ends the “it works on my machine” problem. Like a standard shipping container.
  • Docker is the standard container technology, with three concepts: image (the template/mold), container (the running image/the cookie), and Dockerfile (the written recipe to build the image).
  • The flow: DockerfilebuildImagerunContainers.
  • Compared to virtual machines, containers are lighter and faster because they share the host’s operating system; many fit per server.
  • AWS offers dedicated container services: ECR, ECS, and EKS (next subchapters).

In the next subchapter, we’ll see where to store your images privately and securely: the ECR registry.

Cloud, AWS & Terraform — From Zero to Expert

Chapter 1 · What is cloud computing

Chapter 2 · The cloud market and major providers

Chapter 3 · Regions, availability zones and edge

Chapter 4 · Compute: EC2

Chapter 5 · Storage: S3

Chapter 6 · Networking: VPC

Chapter 7 · Identity and access: IAM

Chapter 8 · Managed databases

Chapter 9 · Why Infrastructure as Code

Chapter 10 · HCL: the Terraform language

Chapter 11 · Providers and state

Chapter 12 · Your first real infrastructure in Terraform

Chapter 13 · Load balancing and auto scaling

Chapter 14 · Serverless with Lambda

Chapter 15 · Messaging and events

Chapter 16 · Content delivery and DNS

Chapter 17 · Containers on AWS

Chapter 18 · Modules: reuse and composition

Chapter 19 · Workspaces and environment management

Chapter 20 · Remote backends and locking

Chapter 21 · Infrastructure testing

Chapter 22 · Terraform in CI/CD

Chapter 23 · Defense in depth

Chapter 24 · Observability: logs, metrics and traces

Chapter 25 · Cost optimization

Chapter 26 · High availability and disaster recovery

Chapter 27 · AWS Well-Architected Framework

Chapter 28 · Serverless architectures at scale

Chapter 29 · Data platforms on AWS

Chapter 30 · Multi-account and landing zones

Chapter 31 · Platform Engineering and Internal Developer Platform

Chapter 32 · Relevant AWS certifications

Chapter 33 · Projects to consolidate what you've learned

Chapter 34 · Resources and community

© Copyright 2024. All rights reserved