Container vs. Image in Docker
A beginner-friendly guide to the two most important words in Docker, explaining what an image is, what a container is, how they relate, and why mixing them up causes so much confusion.
Picture a cookie cutter and a tray of cookies. The cutter is a fixed shape made of metal. It never changes, it never gets eaten, and you can use it as many times as you like. The cookies are the things you actually make with it: each one is real, each one can be decorated differently, and each one eventually disappears. Docker has the same pair of ideas. The cutter is called an image. The cookies are called containers. Almost every beginner mixes these two words up at first, and this guide will make the difference so clear that you will never confuse them again.
1Why Everyone Mixes Them Up
The confusion is natural, because the two words are used together all the time.
When people talk about Docker casually, they often use the words “image” and “container” as if they meant the same thing. A person might say, “I am running an image,” when they really mean they are running a container. Another might say, “I deleted my container,” when they mean they removed an image. In everyday chat, these slips are harmless. But when you are learning, or when something breaks, mixing them up can send you in completely the wrong direction.
The trouble is that the two things are closely connected. You cannot have a container without an image, and an image on its own does nothing until a container is made from it. They live side by side in the same tool, appear in the same lists, and are created by commands that sound alike. It is a bit like confusing a recipe with a meal: they are related, but they are not the same thing.
The good news is that the relationship is simple. An image is something you build and store. A container is something you run. The image is the template, and the container is a live copy made from that template. Once you hold that single sentence in your mind, everything else in Docker becomes easier to understand.
Think of a recipe and a meal. The recipe is written down, stays the same, and can be shared with anyone. The meal is what you cook from it, and you can cook the same recipe many times to feed many people. Nobody would say they are eating a recipe. In the same way, nobody really runs an image; they run a container made from it.
2Some Words You Need First
A short glossary will make everything that follows easy to read.
Image
A read-only package holding an application and everything it needs to run. It is built once and never changes afterwards.
Container
A running or stopped instance created from an image, with its own isolated process, network, and writable storage.
Layer
One building block of an image, recording a set of file changes. Images are stacks of layers.
Dockerfile
A plain text recipe that tells Docker how to build an image, step by step.
Registry
An online library where images are stored and shared, so any machine can download them.
Tag
A friendly label attached to an image, often used for version numbers, so you can refer to it easily.
Volume
A storage area kept outside a container, so important data survives even when the container is removed.
Docker Daemon
The background service that builds images, starts containers, and keeps track of everything.
Whenever you feel unsure, ask yourself one question: “Is this thing a template, or is it alive?” If it is a template that sits still, it is an image. If it is alive, or was alive and has stopped, it is a container.
3What Is a Docker Image?
An image is a frozen, ready-to-use package of an application and its surroundings.
A Docker image is a read-only template. Inside it are the files an application needs: the program itself, the libraries it depends on, some basic operating-system files, and a few settings that describe how to start it. Everything is packed together into one neat bundle. Once an image is built, it is sealed. Nothing can change it. If you want a different version, you must build a new image.
Internally, an image is a stack of layers. Each layer records a small set of file changes, and together the layers add up to a complete file system. Layers are shared between images, which saves space and makes downloads quick. An image also carries a small description that lists its default start command and some environment settings, so that Docker knows what to do when a container is made from it.
Images Just Sit There
An image does not run. It has no active process, uses no memory, and does no work. It simply exists as files on a disk or in a registry. You can keep a thousand images on a computer and none of them will use any processor time. They are like books on a shelf: full of potential, but doing nothing until someone opens one.
An image is like an architect’s finished blueprint for a house. It lists every wall, window, and pipe exactly. The blueprint itself is just paper. You can copy it, store it, and send it across the world, but you cannot live in it.
Some beginners think an image is “a small operating system that is switched off.” That picture is misleading. An image is only a bundle of files and settings. It does not include a running kernel, and nothing inside it is switched on or off. It is inert data.
4What Is a Docker Container?
A container is an image brought to life inside its own isolated space.
A Docker container is what you get when Docker takes an image and actually runs it. Docker uses the image’s layers as a read-only foundation, adds a thin writable layer on top, sets up a private network connection, applies limits on memory and processor use, and then starts the application as an isolated process on the host computer.
From the inside, the application believes it has a private computer of its own. It sees its own files, its own processes, and its own network address. From the outside, the container is just an ordinary process on the host, wrapped in isolation by features of the operating system. This is what makes containers so light: they do not boot a whole new operating system, they just start an isolated process.
Containers Have State and Life
Unlike an image, a container has a life story. It is created, it starts, it runs, it may be paused, it stops, and eventually it is removed. While running, it uses memory and processor time, holds open network connections, and writes messages to logs. It can also change: the application inside can create new files, edit old ones, and delete others. All of those changes go into the container’s own writable layer and never touch the image.
A container is like a house built from the blueprint. It has people living in it, lights switched on, and furniture that gets moved around. You can build many houses from one blueprint, and each house develops its own personality. When a house is knocked down, the blueprint is still safe in the drawer.
Stopping a container does not delete it. A stopped container keeps its writable layer and its settings on disk, just like a switched-off computer keeps its files. It only disappears when you explicitly remove it.
5The Relationship: One Image, Many Containers
The connection between the two is a template-and-copies relationship.
A single image can be used to start as many containers as you like. Each container starts out identical, because they all share the same read-only layers. Yet each one is independent. If one container’s application creates a file, the others do not see it. If one crashes, the others carry on. If you delete one, the rest are unaffected, and the image is still there, ready to make more.
This is why the relationship is often described as one-to-many. Programmers may recognize the same idea from their own work: an image is like a class, which is a definition, and a container is like an object, which is a live instance created from that definition. The class stays put while many objects come and go.
graph TD
I["One Image: read-only template"] --> C1["Container A: own writable layer"]
I --> C2["Container B: own writable layer"]
I --> C3["Container C: own writable layer"]
C1 --> P1["Running process A"]
C2 --> P2["Running process B"]
C3 --> P3["Running process C"]
A cookie cutter can press out a hundred cookies. Each cookie starts the same shape, but you can put sprinkles on one, chocolate on another, and eat a third. What happens to a cookie does not change the cutter or any other cookie.
The Direction of the Arrow
The relationship flows in one direction. Images produce containers. Containers do not automatically produce images. Changing a container does not change the image it came from. This one-way flow is the reason images are trustworthy: whatever happens at runtime, the original template remains exactly as it was built.
6The Journey From Recipe to Running Application
Images and containers appear at different points in the same journey.
To see where each one fits, follow the whole path from an idea to a working application. The first half of the journey is about building and sharing images. The second half is about running containers. The image sits in the middle, as the handover point between the two.
Write the recipe
A developer writes a Dockerfile that describes the starting point, the files to add, and the command to run.
Build the image
Docker follows the recipe and produces an image made of layers. This is the moment the template is created.
Tag and store the image
The image is given a name and version, and is usually pushed to a registry so that other machines can get it.
Pull the image onto a machine
Any computer that needs the application downloads the image, fetching only the layers it does not already have.
Create and start a container
Docker adds a writable layer, connects networking and storage, and starts the application. Now something is truly running.
Stop and remove the container
When the work is done, the container is stopped and removed. The image remains, ready to start a fresh one at any time.
flowchart LR
A["Dockerfile"] -->|build| B["Image"]
B -->|push| C["Registry"]
C -->|pull| D["Image on another machine"]
B -->|run| E["Container"]
D -->|run| F["Container"]
Think of images as the “shipping” half of Docker and containers as the “running” half. Images are what travel between people and machines. Containers are what actually do the work where they land.
7Anatomy Side by Side
A look inside each one shows exactly how they differ.
An image contains only read-only layers and a small configuration. A container contains all of that plus several extra pieces that appear only when it runs. Those extra pieces are what turn a static package into a living thing.
What a Container Adds to an Image
A Writable Layer
A thin layer on top where the running application can create and change files without touching the image.
A Running Process
The actual application, started as an isolated process on the host computer.
Network Settings
A private address, connection to a virtual network, and optionally ports opened to the outside world.
Resource Limits
Caps on how much memory and processor time this container may use.
Mounted Storage
Volumes or folders connected from outside, so data can be kept beyond the container’s life.
Runtime Settings
Environment values, a name, and restart rules chosen at the moment the container is created.
graph TD
subgraph CONTAINER["Container"]
W["Writable layer: temporary changes"]
N["Network, limits, storage, process"]
end
subgraph IMAGE["Image: read-only"]
L3["Layer 3: application code"]
L2["Layer 2: libraries"]
L1["Layer 1: base system"]
end
W --> L3
L3 --> L2
L2 --> L1
A blank theatre script is an image. A live performance of that script is a container. The performance adds actors, lights, an audience, and improvised moments, but the script itself never changes, and the same script can be performed on a hundred different nights.
8The Life Stages of a Container
Containers move through states. Images do not.
One of the clearest differences between the two is that a container has a lifecycle, while an image simply exists. A container moves from one state to another as you work with it. Knowing these states helps you understand what you are looking at when a list of containers shows up on your screen.
stateDiagram-v2
[*] --> Created
Created --> Running: start
Running --> Paused: pause
Paused --> Running: unpause
Running --> Stopped: stop or application exits
Stopped --> Running: start again
Stopped --> Removed: remove
Created --> Removed: remove
Removed --> [*]
Created
The container has been prepared, with its layers and settings, but its application has not started yet.
Running
The application is alive, using memory and processor time, and can receive requests.
Paused
The application is frozen in place. It keeps its memory but does not use processor time until resumed.
Stopped (Exited)
The application has ended, either because you stopped it or it finished its job. The container’s files remain on disk.
Removed
The container and its writable layer are deleted. Anything stored only there is gone for good.
A useful detail is that many containers are designed to finish and stop by themselves. A container that runs a one-time task, such as processing a file, starts, does its job, and exits. Seeing such a container in the “stopped” state is completely normal and does not mean anything went wrong.
Many computers end up cluttered with hundreds of stopped containers that nobody remembers. They still occupy disk space through their writable layers. Remove containers you no longer need, just as you would delete old files.
9Build Time Versus Run Time
Some decisions are baked into the image. Others are chosen when a container starts.
A helpful way to keep the two straight is to sort every choice into “build time” or “run time.” Build-time choices are made once, when the image is created, and are frozen inside it. Run-time choices are made each time you start a container, and they can differ from one container to the next, even if all of them come from the same image.
| Question | Decided At Build Time (Image) | Decided At Run Time (Container) |
|---|---|---|
| What files and programs are inside? | Yes, fixed in the layers | No, but the writable layer can add temporary changes |
| What is the default start command? | Yes, recorded as a default | Can be overridden when the container starts |
| Which environment values are set? | Defaults can be recorded | Can be added or changed at start |
| Which ports are reachable from outside? | Only documented as a hint | Actually opened when the container starts |
| How much memory or processor is allowed? | Not decided | Chosen when the container starts |
| Where does permanent data live? | Not decided | Chosen by attaching volumes |
| What is it called? | A tag or version label | A container name and unique identifier |
This division is what makes Docker so flexible. You build one image with sensible defaults, and then start many containers, each configured differently for its own situation. A test container might use a small memory limit and a test database address, while a production container from the very same image uses a larger limit and the real database.
A car factory builds every car of a model the same way, which is build time. But each owner decides the driver, the destination, and the passengers, which is run time. The factory design and the daily use are separate stories.
Keep passwords, addresses, and other environment-specific details out of the image. Supply them when the container starts. That way the same image works safely in every environment.
10Where the Data Goes
Storage behaves very differently for images and for containers.
An image is immutable, which means its content never changes after it is built. It is stored as read-only layers, and those layers are shared among all images and containers that use them. If ten containers start from the same image, the image layers are stored just once on disk.
A container adds a thin writable layer that belongs only to it. Whenever the application inside writes something, that data lands in the writable layer. When the container is removed, that layer is deleted, and the data goes with it. This surprises many newcomers, who assume that anything a container writes will simply stay around forever.
Volumes: Data That Outlives Containers
For data that must survive, Docker provides volumes. A volume is a storage area managed outside the container’s layers. You attach it to a container when it starts, and the application inside sees it as an ordinary folder. When the container is removed, the volume stays. A new container can then attach to the same volume and continue where the old one left off. Databases, uploaded files, and anything valuable belong in volumes.
flowchart TD
IMG["Image layers: read-only, shared"] --> CON["Container writable layer: lost when container is removed"]
VOL["Volume: kept outside, survives removal"] --> CON
CON --> APP["Application inside the container"]
Problem
Storing important data, such as a customer database, only inside the container’s own writable layer.
Why It’s Harmful
When the container is removed or replaced during an update, the data disappears with it, and it cannot be recovered.
Correct Approach
Attach a volume or use an external storage service for all data that must survive, and treat the container itself as disposable.
11Names and Identities
Both images and containers can be told apart, but they are labeled in different ways.
How Images Are Named
An image is usually referred to by a name and a tag, such as the name of an application followed by a version label. The tag is only a convenient sticker, and it can be moved from one image to another. Tomorrow, the “latest” label might point to a completely different image than it does today. Underneath, every image also has a unique fingerprint, called a digest, that is calculated from its content and never changes for that content.
How Containers Are Named
A container has a long unique identifier assigned by Docker, and a human-friendly name. If you do not choose a name, Docker invents a playful one, such as a combination of an adjective and a famous scientist. Container names must be unique on a machine, because they are used to find and manage a specific container.
Name and Tag
A repository name plus a version label. Handy for people, but the label can be moved.
Digest
A content-based fingerprint. It identifies exactly one image forever.
Container ID
A unique long identifier generated when the container is created.
Container Name
A friendly name, either chosen by you or generated by Docker, unique on the machine.
The tag named “latest” does not mean the newest or safest image. It is just a label with a default value. Relying on it can cause two machines to run different code without anyone realizing. Prefer explicit version tags or digests for anything important.
12What Travels and What Stays Home
Only images are shared through registries. Containers stay on the machine where they run.
When developers share their work, they share images. An image is pushed to a registry, and anyone with access can pull it. A container, by contrast, is a live thing that belongs to a specific machine. You do not upload a running container to a registry. If you want another machine to run the same application, it downloads the image and starts its own fresh container.
This explains a big benefit of Docker. Because the image carries everything the application needs, and because it never changes, a container started from it will behave the same on a laptop, a test server, or a production cluster. The image is the promise of sameness, and the container is where that promise is put to work.
sequenceDiagram
participant Dev as Developer machine
participant Reg as Registry
participant Srv as Production server
Dev->>Dev: Build image
Dev->>Reg: Push image
Srv->>Reg: Pull image
Reg-->>Srv: Send image layers
Srv->>Srv: Create and start a container
A chain of restaurants shares one recipe book, which is the image. Every branch cooks its own meals from it, which are the containers. You would never mail a half-eaten meal from one branch to another. You send the recipe, and each branch cooks fresh.
13Updating: Replace, Do Not Repair
The relationship between images and containers shapes how updates are done.
Because an image never changes, updating an application means building a new image with the changes, and then replacing the old container with a new container made from the new image. You do not log into a running container and patch it by hand. This approach is often called immutable infrastructure: the pieces are never modified in place, only replaced.
The benefit is predictability. If the new version has a problem, you simply start containers from the previous image again, which is a fast and reliable rollback. Nothing was edited by hand, so nothing is unknown. Both versions exist as clean images, and the containers are disposable.
Change the code and build a new image
The new image is a separate, fully tested package with its own version label.
Start a new container from the new image
The new container is prepared next to the old one, so you can check that it is healthy.
Switch traffic and remove the old container
Once the new container is working, traffic is directed to it and the old container is stopped and removed.
Keep the old image for rollback
If anything goes wrong, a container from the old image can be started again within seconds.
Problem
Logging into a running container to install packages or edit files by hand, and then saving that container as a new image to keep the changes.
Why It’s Harmful
Nobody can tell exactly what is inside the resulting image, the steps cannot be repeated, and the image cannot be rebuilt from a recipe. It creates a mystery box that nobody dares touch.
Correct Approach
Put every change into the Dockerfile, rebuild the image, and replace the container. The recipe then documents exactly how the image is made.
14Removing Things: Which Depends on Which
Cleaning up is easier once you know that containers depend on images, but not the other way around.
A container is built on top of an image’s layers, so Docker will usually refuse to delete an image that still has containers made from it, even stopped ones. The rule of thumb is simple: remove the containers first, and then the images. Going in that order avoids confusing error messages.
Over time, both kinds of clutter accumulate. Old images that nobody uses take up space, and so do stopped containers with their writable layers. There are also dangling images, which are untagged leftovers from rebuilds. Regular tidying keeps a machine healthy and prevents the classic problem of a disk that mysteriously fills up.
Stopped Containers
Remove containers that have finished their work and that you no longer need to inspect.
Unused Images
Remove images that no container uses and that you can easily rebuild or download again.
Dangling Images
Untagged image layers left behind after rebuilds. They are safe candidates for removal.
Unused Volumes
Remove only after checking carefully, because volumes may hold data that cannot be recreated.
Deleting containers and images is usually safe, because both can be recreated. Deleting a volume can destroy real data. Always double-check what a volume contains before removing it.
15Security: Two Different Places to Look
Images and containers each carry their own security concerns.
Image security is about what is inside the package before it ever runs. Does the base image come from a trusted source? Do any of its layers contain software with known weaknesses? Did someone accidentally include a password? Scanning tools examine images for these problems, and the best time to catch them is before the image is deployed.
Container security is about how the running instance behaves and what it is allowed to do. Does it run as an administrator, or as an ordinary user? Can it access parts of the host that it does not need? Are its memory and processor use limited? Are its network connections restricted? Many of these settings are chosen at run time, so two containers from the very same image can be very different in how safe they are.
Image Security Habits
- Start from small, official, well-maintained base images
- Scan images for known vulnerabilities before deployment
- Never bake passwords or keys into any layer
- Rebuild images regularly to pick up security fixes
- Prefer pinned versions or digests over moving labels
Container Security Habits
- Run the application as an ordinary user, not as an administrator
- Set memory and processor limits
- Grant only the permissions and storage access truly needed
- Supply secrets at run time through a protected source
- Restrict network access to only what the application requires
Checking the recipe for spoiled ingredients is like scanning an image. Keeping the kitchen clean, the doors locked, and the cooks supervised while the meal is prepared is like securing a container. A safe restaurant needs both.
16Watching Them: Logs, Metrics, and Health
Only containers produce live signals, but images have things worth checking too.
Because an image is static, there is little to monitor about it in real time. What you check is its size, its history of build steps, its age, and the results of security scans. These are questions about quality and hygiene rather than behavior.
A container, being alive, produces plenty of signals. Its application writes messages that Docker captures as logs. Docker can report how much processor, memory, and network the container is using. A container can define a health check, which is a small test that Docker repeats regularly to confirm the application is really working. Docker also announces events, such as a container starting, stopping, or being killed, and monitoring tools can react to them.
Size and History
Shows which build steps added the most weight and helps you keep images lean.
Vulnerability Scans
Reports known weaknesses in the software packed inside the layers.
Logs
The messages the application prints. Send them to a central place so they survive container removal.
Resource Statistics
Live figures for processor, memory, and network use, revealing trouble before it becomes an outage.
Health Status
The outcome of the container’s own self-checks, telling you whether the application is truly healthy.
Events
A stream of announcements about starts, stops, and failures, ideal for alerts and automation.
17Strengths and Trade-offs of the Split
Separating the template from the running instance is a powerful design, but it takes some getting used to.
Advantages
- One tested image produces identical containers everywhere
- Images can be shared, versioned, and rolled back easily
- Containers are disposable, so updates and repairs are simple
- Many containers share the same layers, saving disk space
- Build-time and run-time choices stay cleanly separated
- Environment differences are handled by settings, not by rebuilding
Disadvantages / Trade-offs
- Beginners often confuse the two terms and the commands that go with them
- Data in a container’s writable layer is lost unless volumes are used
- Forgotten stopped containers and old images pile up and fill disks
- Moving tags like “latest” can cause surprising differences between machines
- Extra care is needed to keep secrets out of images
18Side-by-Side Comparison
A single table lining up every important difference.
| Feature | Docker Image | Docker Container |
|---|---|---|
| What it is | A read-only template of layers and settings | A running or stopped instance made from an image |
| Is it running? | Never | When started, yes |
| Can it change? | No, it is immutable | Yes, through its writable layer |
| Uses memory and processor? | No, only disk space | Yes, while running |
| How it is made | Built from a Dockerfile | Created from an image |
| How many from one? | Many containers per image | Each container comes from exactly one image |
| Can it be shared through a registry? | Yes | No, only the image it came from |
| Lifetime | Until you remove it | Created, running, stopped, then removed |
| Identified by | Name, tag, and digest | Container ID and name |
| Programming comparison | Like a class | Like an object |
| Everyday comparison | Recipe, blueprint, cookie cutter | Meal, house, cookie |
19Real-World Examples
Seeing the pair at work in everyday situations makes the difference stick.
A Team Releasing a New Version
A team builds an image for version two of its web application and pushes it to a registry. Servers pull the new image and start fresh containers from it, while the old containers from version one are removed. The image is the release, and the containers are its running copies.
A Website Handling a Traffic Rush
When traffic surges, the platform starts more containers from the same image within seconds. When traffic falls, it removes the extra containers. The image never changes, only the number of containers does.
A Developer Testing Safely
A developer starts a container from a database image, experiments freely, and then removes the container. The image remains untouched, so the next experiment starts from a perfectly clean state.
A One-Time Data Job
A company runs a container from a report-generating image every night. The container starts, produces the report, and exits. It costs nothing while it is not running, and the image waits quietly for the next night.
A Rollback After a Bad Release
A new release has a serious bug. The team stops the new containers and starts containers again from the previous image, restoring service in moments because the old image was kept unchanged.
20Patterns and Anti-Patterns
Good habits keep the pair working for you rather than against you.
Helpful Patterns
Build Once, Run Anywhere
Build a single image, test it, and promote that exact image through every environment. Only the run-time settings change, never the image.
Disposable Containers
Design every container so it can be destroyed and recreated at any moment without loss. Keep data in volumes and configuration in settings.
Version Everything Explicitly
Give every image an explicit, meaningful version label, and prefer exact versions or digests in production, so you always know what is running.
More Anti-Patterns to Avoid
Problem
Building a separate image for every environment, such as one for testing and another for production, with different contents.
Why It’s Harmful
What you tested is no longer what you deploy. Bugs appear only in production because the two images are not truly the same.
Correct Approach
Build one image and supply environment-specific settings when each container starts.
Problem
Treating a container like a small server: keeping it running for months, logging in to change it, and being afraid to remove it.
Why It’s Harmful
The container drifts away from its image, nobody knows what changed, and losing it would mean losing hidden work.
Correct Approach
Treat containers as short-lived and replaceable. Fix problems by updating the image and starting a new container.
Problem
Never cleaning up, so that hundreds of stopped containers and forgotten images pile up on every machine.
Why It’s Harmful
Disk space quietly disappears, and eventually builds and container starts fail because the disk is full.
Correct Approach
Schedule regular cleanup of unused containers, images, and cache, and monitor disk usage.
21Best Practices Checklist
A short list to keep your images tidy and your containers dependable.
Keep the vocabulary straight
Say “build an image” and “run a container.” Precise words prevent precise mistakes, especially in team conversations.
Build small, clean images
Use small base images and multi-stage builds so images are quick to move and have little to attack.
Use explicit tags or digests
Avoid relying on a moving label so that every machine runs exactly the same image.
Put data in volumes
Anything that must last belongs outside the container’s writable layer.
Configure at run time, not build time
Pass environment-specific settings and secrets when the container starts so one image serves every environment.
Replace containers instead of repairing them
Update by building a new image and starting a new container, keeping the old image available for rollback.
Limit and secure running containers
Run as an ordinary user, set resource limits, and grant only the access the application needs.
Clean up regularly
Remove stopped containers, unused images, and old cache, and be careful before touching volumes.
22Frequently Asked Questions
An image is a read-only template that holds an application and its dependencies, while a container is a running or stopped instance created from that template.
No. Every container is created from an image, which supplies its read-only layers and its default settings. The image must exist on the machine before the container can be made.
Yes, as many as you like. Each container is independent, with its own writable layer, so changes in one never affect the others or the image.
No. Changes go into the container’s own writable layer. The image is read-only and stays exactly as it was built.
Anything stored only in the container’s writable layer is deleted with it. Data stored in a volume or an external service is kept.
It uses no processor or memory, since nothing is running, but it still occupies some disk space for its writable layer and settings until it is removed.
Usually because a container, even a stopped one, was created from it. Remove the containers first, and then remove the image.
Docker can save a container’s current state as a new image, but this is discouraged for normal work because the result cannot be rebuilt from a recipe. Changing the Dockerfile and rebuilding is the cleaner, repeatable way.
Images. Registries store and distribute images. Each machine that downloads an image starts its own containers from it.
Images usually take most of the space, since they hold all the layers, but those layers are shared. Each container adds only a thin writable layer, though many forgotten containers can add up.
23Summary and Key Takeaways
A Docker image and a Docker container are two halves of one idea. The image is the template: a sealed, read-only stack of layers and settings that is built once, versioned, shared through registries, and never changed. The container is the live copy: an image brought to life with a thin writable layer, a running process, its own network, and its own limits. One image can produce countless containers, and each container has a lifecycle from creation through running and stopping to removal, while the image simply waits unchanged. Build-time decisions live in the image, run-time decisions live in the container, and data that must last belongs in volumes. Once you remember that you ship images and run containers, and that containers are meant to be replaced rather than repaired, Docker becomes a calm and predictable tool.
Key Takeaways
- An image is a template, a container is an instance — the image is read-only and never runs, and the container is what actually runs.
- One image, many containers — every container gets its own writable layer, so changes in one never affect the image or its siblings.
- Images are built, containers are created — a Dockerfile builds an image, and Docker creates and starts a container from that image.
- Only images travel — registries store images, and each machine starts its own fresh containers from them.
- Build time versus run time — keep environment-specific settings and secrets out of the image and supply them when the container starts.
- Container data is temporary — the writable layer disappears with the container, so keep important data in volumes.
- Replace, do not repair — update by building a new image and starting a new container, and keep the old image for easy rollback.