Docker Images

Docker Images

What is a Docker Image?

A Docker image is a lightweight, standalone, and executable package that contains everything needed to run an application. It includes:
✔ Source Code – The application files.
✔ Runtime – Execution environment like Python, Node.js, etc.
✔ Libraries & Dependencies – Required packages.
✔ Configuration Files – System settings, environment variables, etc.

How Docker Images Work

  Docker images act as blueprints for containers.
•  When you run a container, it is created from an image.
•  Images are read-only; containers are instances of these images.

Working with Docker Images

1️⃣ Pulling an Image from Docker Hub

Docker Hub hosts pre-built images. To download an image, use:

docker pull nginx

This pulls the nginx image from Docker Hub.

2️⃣ Listing Available Images

To view all downloaded images on your system:

docker images

You’ll see a list with the image name, tag, size, and ID.

3️⃣ Removing an Image

You’ll see a list with the image name, tag, size, and ID.

docker rmi <image_id>

Building Custom Docker Images

You can create your own Docker image using a Dockerfile.

1️. Create a Dockerfile

Create a file named Dockerfile and add the following:

Dockerfile


# Base image
FROM python:3.9

# Set working directory
WORKDIR /app

# Copy application files
COPY . /app

# Install dependencies
RUN pip install -r requirements.txt

# Run the application
CMD [“python”, “app.py”]

2️⃣ Build the Image

docker build -t my_python_app.

3️⃣ Run a Container from the Image

docker run -d -p 5000:5000 my_python_app

Now your custom application is running inside a container!

Tagging & Pushing Images to Docker Hub

1️⃣ Tag an Image

docker tag my_python_app username/my_python_app:v1

2️. Push an Image to Docker Hub

docker push username/my_python_app: v1

Now others can download your image using docker pull username/my_python_app:v1.

Conclusion

•  Docker Images are the foundation of containers.
•  You can use pre-built images from Docker Hub or create custom images using a Dockerfile.
•  Images make applications portable, scalable, and easy to deploy.

Chatbot