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

docker image graph

But how exactly does it do that?

Image Layers

Docker images are made of layers.

image 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?

I don't know meme

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.

high-spec pc

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.

docker image layers

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.

docker image as instructions

(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.

dockerfile to docker image

Here’s what that looks like:

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

simple Dockerfile

Then you add a package.json file.

simple Dockerfile

Install those dependencies.

And finally, add the source code.

simple Dockerfile

Fee from Anime Coders

How did you like today's email?

Login or Subscribe to participate

Keep Reading