Docker - Day -03
What is a Container Image? The Blueprint for Your App's Perfect Home!
If a container is like a running application, then a container image is its blueprint or a perfect, pre-packed moving box, ready to be duplicated and used.
An image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, and settings.
What's inside a Container Image?
A container image is essentially a snapshot of a file system, structured in layers. These layers make images incredibly efficient:
Base Layer: Often contains a minimal operating system (like Alpine Linux) and foundational libraries. Many images can share the same base layer.
Application Layers: Subsequent layers add your application's specific dependencies, libraries, and finally, your application code itself.
Read-Only: Once an image is built, it's read-only. This immutability guarantees consistency every time you use it.
There are two important principles of images:
Images are immutable. Once an image is created, it can't be modified. You can only make a new image or add changes on top of it.
Container images are composed of layers. Each layer represents a set of file system changes that add, remove, or modify files.
These two principles let you extend or add to existing images. For example, if you are building a Python app, you can start from the Python image and add additional layers to install your app's dependencies and add your code. This lets you focus on your app, rather than Python itself.
How Images and Containers Relate
Image = Blueprint/Template (Static):
It's the inert, shareable package of your application and its environment. You store images in registries (like Docker Hub).
Container = Running Instance (Dynamic):
When you "run" an image, you create a container. This container is an active process that takes the image's read-only layers and adds a thin, writable layer on top for any changes or temporary data generated by the running application.
Why are Container Images so Important?
Consistency: An image captures your entire application environment at a specific point in time, guaranteeing that it will run exactly the same way, everywhere. This solves the "it works on my machine!" problem.
Portability: Once built, an image can be easily shared and pulled from a registry to any compatible host, then run as a container without compatibility issues.
Efficiency (Layering): Because images are built in layers, if only a small part of your application changes, only that specific layer needs to be updated and transmitted, not the entire image. This saves bandwidth and storage.
Version Control: Images can be tagged with versions (e.g., myapp:1.0, myapp:latest), allowing you to manage and roll back to specific application states easily.
Foundation for DevOps: Images are central to Continuous Integration/Continuous Deployment (CI/CD) pipelines, enabling automated, reliable deployments.
Finding images
Docker Hub is the main marketplace for finding and sharing Docker images. It hosts over 100,000 developer-created images, which you can easily search for and run via Docker Desktop.
Docker Hub features "Docker Trusted Content" for reliable options, including:
Docker Official Images: Curated, secure, and popular starting points (e.g., Redis, Memcached).
Docker Verified Publishers: High-quality images from commercial providers.
Docker-Sponsored Open Source: Images from open-source projects supported by Docker.
These images allow you to quickly launch services or use base images (like Node.js) to build your own custom applications.
Try it out
Use the following procedure to run a Container.
Open Docker Desktop and select the Search field on the top bar.
Specify welcome-to-docker or any image that you want.

3. Once the image is successfully pulled, select the Run.

4. Expand the Optional Settings.

5. In the Container Name, specify welcome-to-docker.
6. In the Host Port, specify 8080.

7. Select Run to start this container.
8. Go to the container Tab and open the url in browser.

