Instantiating Containers from Docker Images
In this lesson, you will learn how to breathe life into a static Docker image by transforming it into a living, breathing container instance.
From Static to Dynamic
Think of a Docker image as a recipe stored in a cookbook. It contains all the instructions, dependencies, and code required to run an application, but it is entirely passive. It sits on your disk, consuming storage space but performing no work.
To make that recipe a meal, you must "cook" it. In the Docker world, this process is called instantiation. When you instantiate a container, you are asking the Docker daemon to take that static image, set up a writable filesystem layer on top of the read-only image layers (thanks to our Copy-on-Write strategy), and start the execution process.
The Runtime Command
To perform this transformation, we use the docker run command. When you execute this, the Docker client sends a request to the daemon, which then coordinates with the runtime (like runc) to spin up the container process.
For example, if you want to instantiate a container from the nginx image, you would run:
docker run -d nginx
Here is what happens behind the scenes:
- The Daemon checks the Content Store: It verifies if the
nginximage is available locally. - Layer Assembly: It prepares the union filesystem, placing a fresh, empty writable layer over the read-only image layers.
- Execution: It tells the runtime to start the primary process defined in the image metadata.
- Instantiation: You now have a running container instance that is isolated from your host system but built upon the immutable foundation of your image.
Once this command finishes, the image remains unchanged (it is still just a recipe), but you have successfully created an active, ephemeral instance that exists in memory. You can create dozens of separate containers from the exact same image, each maintaining its own unique writable layer, ensuring that your application starts from the same reliable base every single time.
Key Takeaway: Instantiating a container uses the docker run command to move an application from a static, read-only image state into an active, writable process environment.