Chapter 1 of 16 · Visual guide

Docker fundamentals

Docker packages an app and its whole environment into one image, then runs that image anywhere as an isolated container.

key idea / Docker itselfcontainer / good pathhost / watch outproblem / blockedneutral

Why Docker exists

The classic bug is a program that works on one machine and not another. Docker removes the difference by shipping the environment too.

Why Docker existsIt works on my laptopNode 20, libssl 3packImageapp + runtime + libsrunRuns the same anywherelaptop, CI, serverAn image is the whole environment frozen into one immutable file.
Package the app together with its environment, and the machine stops mattering.

The four moving parts

You type commands into the CLI; a background daemon does the work.

The four moving partsThe docker CLI talks to the daemon. The daemon stores images, runs containers, and pulls and pushes images to a registry.docker CLIwhat you typeDocker hostDocker daemon (dockerd)builds, runs, distributesImagesread-onlyContainersrunning processesstored on disk, run as processesREST APIRegistryDocker Hub, ECRpush / pull

Image versus container

The image is the blueprint. A container is a running copy of it with a thin writable layer.

Image versus containerAn image is a stack of read-only layers. A container is the same stack plus one writable layer on top.Image (read-only)Container (image + one writable layer)Your app codeYour app codenpm packagesnpm packagesNode.js runtimeNode.js runtimeAlpine baseAlpine baseWritable layer: logs, temp filesnever changes after builddeleted with the container
The writable layer is why a container can write logs without ever changing its image.

Where data survives

Anything written to the container layer disappears with the container, so persistent data belongs in a volume.

Where data survivesA container writable layer is deleted when the container is removed. A volume lives outside the container and survives.ContainerWritable layerdeleted on docker rmApp processpostgres, node, nginxVolumemanaged by Docker, outsidemounted at startsurvives docker rm: keep databases here

Try it yourself

Run these in order. Version numbers on your machine will differ.

  1. Step 1 · Client and daemon

    docker version prints two blocks. Client is the command you typed. Server is the daemon. If the Server block is missing, the daemon is not running.

    $ docker version
    Client:
     Version:    27.3.1
    Server:
     Engine:
      Version:    27.3.1
  2. Step 2 · What the daemon is holding

    docker info is the daemon’s inventory: how many images and containers it has, and which storage driver it uses.

    $ docker info --format 'containers={{.Containers}} images={{.Images}} driver={{.Driver}}'
    containers=0 images=0 driver=overlayfs
  3. Step 3 · An image is not a container yet

    Pull stores an image. Nothing is running until run.

    $ docker pull hello-world
    $ docker images
    REPOSITORY    TAG       IMAGE ID       SIZE
    hello-world   latest    d2c94e258dcb   13.3kB
    $ docker ps
    CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
  4. Step 4 · The four objects

    You just used all four. The registry served hello-world. The daemon stored the image. docker ps is empty because you have not created a container. The next chapter does that.

Recap

Quick check

You ran docker pull hello-world and docker ps shows nothing. Is something wrong?
Show answer

No. Pull only stores the image. A container exists only after docker run, and hello-world exits immediately, so docker ps -a would show it.