📘Cisco DevNet Associate (200-901 DEVASC)
1. What is a Docker Image?
A Docker image is like a blueprint for a container. It contains:
- The application code (e.g., a web app or API)
- System libraries and dependencies the app needs
- Configuration and environment settings
Think of it as a ready-to-run package. You don’t need to install extra software manually—the image already has what’s needed.
Exam Tip: Remember, images are read-only templates, while containers are running instances of those images.
2. Why Use Docker Images in a Local Environment?
Using Docker images locally is common for developers because it allows you to:
- Run apps without installing them directly on your computer.
Example: You can run a Python app in a container without installing Python globally. - Ensure consistency.
If the app works in the container on your machine, it will work the same on another machine or in production. - Isolate environments.
You can run multiple apps with different dependencies without conflicts. - Quickly test new software versions.
You can pull a new Docker image version and test it without changing your local system.
3. Key Commands for Using Docker Images Locally
Here’s what you need to know for the exam and daily usage:
a. Pulling an Image
Before running an image, you need to download it from a registry (like Docker Hub):
docker pull <image_name>:<tag>
<image_name>→ Name of the image (e.g.,nginx,python)<tag>→ Version (e.g.,3.2,latest). If not specified,latestis assumed.
Example:
docker pull python:3.11
This downloads Python version 3.11 image to your local machine.
b. Listing Local Images
To see which images are available locally:
docker images
You’ll see:
- Repository (image name)
- Tag (version)
- Image ID
- Size
c. Running a Container from an Image
To start a container:
docker run -it --name mycontainer <image_name>:<tag>
-it→ Interactive mode (useful for testing)--name→ Give a custom name to your container<image_name>:<tag>→ Image to run
Example:
docker run -it --name dev-python python:3.11
This creates a running Python environment in a container named dev-python.
d. Checking Running Containers
docker ps
- Shows currently running containers.
- Add
-ato see all containers, including stopped ones:
docker ps -a
e. Stopping and Removing Containers
Stop a container:
docker stop <container_name_or_ID>
Remove a container:
docker rm <container_name_or_ID>
Exam Tip: Don’t confuse images and containers. Images are templates; containers are active instances.
4. Using Docker Images to Build a Local Development Environment
Developers use Docker images locally to:
- Test code safely without affecting the main system.
- Use multiple versions of tools (e.g., Node.js 18 and Node.js 20) on the same computer.
- Simulate production environment by running containers that mirror the real environment.
5. Optional: Customizing Images with Dockerfile
You can also create your own Docker image using a Dockerfile:
- Write instructions in a file called
Dockerfile - Build the image:
docker build -t my-custom-image:1.0 .
- Run it like any other image:
docker run -it my-custom-image:1.0
This is useful if your app needs specific libraries or settings.
6. Common Docker Registries
Docker images are often stored in registries:
- Docker Hub → Public images (e.g.,
python,nginx) - Private registry → Company-specific images
- GitHub Container Registry → Supports public and private images
Exam Tip: Know that
docker pullgets images from registries anddocker runlaunches them locally.
7. Summary for the Exam
- Docker image = blueprint; container = running instance.
- Use images locally to create isolated, consistent environments.
- Key commands:
docker pull→ download imagedocker images→ list local imagesdocker run→ start containerdocker ps→ check running containersdocker stop/docker rm→ stop/remove containers
- Custom images via Dockerfile can tailor your environment.
- Registries store images and allow sharing.
