Learn how containers work by playing Tic-Tac-Toe

By Sean Scott

Elevator Pitch

Can a game of Tic-Tac-Toe reveal the inner mechanisms of containers and help us understand more effective ways of building and using them?

Absolutely! Tic-Tac-Toe provides a perfect metaphor for container layers, the amazing component behind a surprising number of container features!

Description

The Docker community struggles to answer the question, “What’s a container?” One common answer, “Containers are like lightweight virtual machines,” is a poor analogy and doesn’t answer the question or tell us anything about containers!

What are containers, then, and how do they work? Truly understanding containers means scratching the surface to expose the “layers” below! Layers are the magical sleight-of-hand lurking beneath the surface of containers. They’re the secret sauce behind the speed and efficiency containers and show up in the most unexpected places! Without understanding layers—and union filesystems implement them—you can’t fully appreciate how containers work or use them to their fullest!

“Wait! You said ‘simple.’ This sounds like a technical deep dive into the Linux kernel!”

Have no fear—I promise there’s nothing technical here, just a game of Tic-Tac-Toe guaranteed to open your eyes to the clever illusion made possible by layers! Once you know the trick it’s impossible to un-see. Unlocking this understanding will change how work with containers!

Notes

While researching material for my book on running Oracle on Docker, I was drawn down a fascinating rabbit hole on container layers. They show up EVERYWHERE, but most people don’t understand them or, at best, fail to appreciate how ubiquitous they are.

Without layers, containers couldn’t start quickly or scale efficiently. They’re why containers are stateful and ephemeral while images are stateless and immutable. They show up in builds, caching, and tags, too.

Knowing how Docker uses layers unlocks understanding for writing better Dockerfiles and building smaller, more efficient images, but that means explaining layers—what they are and how they work. In my experience, straightforward, visual analogies are the fastest path to teaching new, technical concepts. A good analogy is simple; something people can picture and manipulate alongside the thing you’re teaching.

For layers, that’s a game of Tic-Tac-Toe! With that, I explain:

  • Overlay/union filesystems
  • The difference between images and containers
  • Why containers start quickly and scale efficiently
  • Immutability, state, and ephemeral-ness
  • Dockerfiles, image builds and tags, caching, and repositories
  • Persistence and when and why you should use volumes

No code, no jargon, and no technical deep dives! The coolest part? It doesn’t matter if you’re new to Docker or an old hand. People who’ve been using Docker for years have epiphanies when they “see” how layers implement container features!