Getting Started with Docker: A Practical Guide to Containerization

Docker revolutionizes software deployment by packaging applications with all their dependencies into lightweight, portable containers. Unlike virtual machines, containers share the host OS kernel, making them faster and more resource-efficient.

Containers isolate your app from the environment, eliminating “it works on my machine” issues. They run consistently across development, testing, and production. This tutorial walks you through the essential steps to containerize your own application.

Article illustration

1. Install Docker and Run a Test Container

Download Docker Desktop from the official site and install it. Verify the installation by opening a terminal and running:

docker run hello-world

This command pulls a small test image and runs a container that prints a success message. You now have a working Docker environment.

2. Create a Dockerfile for Your Application

A Dockerfile is a text file with instructions to build a custom image. For a simple Python web app, create a file named Dockerfile (no extension) with:

  • FROM python:3.9-slim – base image
  • WORKDIR /app – set working directory
  • COPY requirements.txt . – copy dependency file
  • RUN pip install -r requirements.txt – install packages
  • COPY . . – copy all application files
  • CMD ["python", "app.py"] – command to run the app

3. Build and Run the Custom Image

Navigate to your project folder (where the Dockerfile is located) and build the image:

docker build -t my-python-app .

Then run a container from the image:

docker run -p 5000:5000 my-python-app

Your application is now running inside a container and accessible at http://localhost:5000.

4. Manage Containers and Use Docker Compose

List running containers with docker ps. Stop one with docker stop <container_id>. For multi‑container setups (e.g., app + database), create a docker-compose.yml file and run docker-compose up. This starts all services with a single command.

Docker containerization simplifies development, testing, and deployment. Start small, experiment, and soon you’ll be shipping consistent environments everywhere.

sarah antaboga
Author: sarah antaboga

Leave a Reply

Your email address will not be published. Required fields are marked *