Docker Explained: What It Is and How to Get Started Using Containers

Docker is a platform that packages applications and their dependencies into lightweight, portable containers. Unlike virtual machines, containers share the host OS kernel, making them faster, smaller, and more efficient. This guide covers the basics and shows you how to run your first container.

Think of a container as a standardized unit of software. It includes everything your app needs: code, runtime, system tools, libraries, and settings. Docker ensures your application runs consistently across different environments—from your laptop to production servers.

Article illustration

Installing Docker

Download Docker Desktop for Windows, macOS, or Linux from the official site. Follow the installer, and once installed, open a terminal and verify with:

docker --version

Running Your First Container

Pull an image from Docker Hub, a public registry of pre‑built containers. For example, the official Nginx web server:

docker pull nginx

Then run it in detached mode, mapping port 80 inside the container to port 8080 on your host:

docker run -d -p 8080:80 nginx

Open http://localhost:8080 in your browser—you should see the Nginx welcome page.

Key Docker Commands

  • docker ps �� list running containers
  • docker stop <container-id> – stop a container
  • docker images – list downloaded images
  • docker rmi <image-name> – remove an image

Creating a Simple Dockerfile

A Dockerfile defines how to build your own image. Create a file named Dockerfile (no extension):

# Use an official Python runtime as base
FROM python:3.10-slim

# Set the working directory inside the container
WORKDIR /app

# Copy the current directory contents into the container
COPY . .

# Install dependencies if any (example: Flask)
RUN pip install flask

# Run app.py when the container launches
CMD ["python", "app.py"]

Build the image with:

docker build -t my-python-app .

Then run it:

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

Conclusion

Docker simplifies development and deployment by eliminating “it works on my machine” issues. Start with basic commands, explore Docker Hub for ready‑to‑use images, and gradually build your own containers. Master these fundamentals to unlock the full power of containerization.

sarah antaboga
Author: sarah antaboga

Leave a Reply

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