A Docker image is like a magical capsule that contains every tool your program needs.

But how exactly does it do that?

Image Layers

Docker images are made of layers.

Each layer adds something new to the filesystem.

Stack these layers together, and you get a complete filesystem ready to run your code.

Sounds confusing?

Here’s the easiest way to understand it.

Imagine you just brought a brand-new computer with two Nvidia RTX 5090 GPUs, Ryzen 7 9800X3D CPU & 64 GB RAM.

The specs are good on paper. But can it run JavaScript?

You need to know.

Think about what you need to install to set it up.

About six things.

  1. an operating system, like Alpine Linux.

  2. a package manager like APK.

  3. a runtime like Node.js to run the JavaScript.

  4. JS package manager like npm.

  5. the dependencies from your package.json file.

  6. The code.

In each of these steps, you add something new to the filesystem.

Each of them becomes a layer in a Docker image.

So a Docker image is basically a list of instructions for recreating the filesystem your program needs.

(Of course, there are many more instructions than installing, like adding or deleting files.)

Dockerfile

A Dockerfile is just a cleaner way to write those instructions.

Here’s what that looks like:

You start with a base image that already has Linux Alpine, Node.js, and npm.

Then you add a package.json file.

Install those dependencies.

And finally, add the source code.

Fee from Anime Coders

How did you like today's email?

Login or Subscribe to participate

Keep Reading

No posts found