Docker Basics

By: Yasas Harshana | Date: 2025-07-07

Docker Basics

Docker is a powerful tool that helps developers and DevOps engineers build, ship, and run applications inside lightweight containers. If you're just getting started with DevOps or containerization, understanding Docker is essential.

What is Docker?

Docker is a platform for developing, packaging, and running applications in isolated environments called containers. These containers are lightweight, portable, and consistent across environments, making deployments more predictable and scalable.

Why Use Docker?

  • Consistency: Ensures the same environment in development, testing, and production.
  • Portability: Runs on any system with Docker installed.
  • Efficiency: Uses fewer resources than virtual machines.
  • Isolation: Keeps applications and dependencies separated.

Key Concepts

| Term | Description | |--------------|-----------------------------------------------------------------------------| | Image | A snapshot of a container, including the application and its dependencies. | | Container | A running instance of an image. | | Dockerfile | A script with instructions to build a Docker image. | | Docker Hub | A public registry for sharing Docker images. | | Volume | Used to persist data generated by containers. | | Network | Allows containers to communicate with each other. |

Basic Docker Commands

Here are some essential Docker commands to get started:

```bash

Check Docker version

docker --version

Pull an image from Docker Hub

docker pull nginx

Run a container from an image

docker run -d -p 8080:80 nginx

List running containers

docker ps

Stop a container

docker stop

Remove a container

docker rm

Remove an image

docker rmi nginx ````

Writing a Simple Dockerfile

A Dockerfile defines the environment for your application. Here's a basic example:

```Dockerfile

Use an official Python base image

FROM python:3.10-slim

Set working directory

WORKDIR /app

Copy code files

COPY . .

Install dependencies

RUN pip install -r requirements.txt

Run the application

CMD ["python", "app.py"] ```

Build and run your image:

bash docker build -t my-python-app . docker run -d -p 5000:5000 my-python-app

Conclusion

Docker simplifies the process of building, testing, and deploying applications. Once you grasp the basics, you'll unlock powerful workflows for DevOps, CI/CD, and scalable infrastructure.

In future articles, we'll explore Docker Compose, Docker volumes, and integrating Docker with CI pipelines.


Next Steps: