DEV Community

CliffordIsaboke
CliffordIsaboke

Posted on

Getting Started with Docker: A Practical Guide for Beginners

Introduction

Docker has revolutionized the way we build, ship, and run applications. Whether you're a backend developer, DevOps engineer, or just curious about containers, Docker is a tool worth learning.

In this guide, we’ll cover:

What Docker is

How it works

Installing Docker

Key concepts: images, containers, Dockerfiles

Practical examples

Tips and best practices
Enter fullscreen mode Exit fullscreen mode

πŸ“¦ What is Docker?

Docker is a platform that allows you to develop, ship, and run applications inside containers. Containers are lightweight, standalone, and executable packages that include everything needed to run a piece of softwareβ€”code, runtime, libraries, and dependencies.
βš™οΈ How Does Docker Work?

Docker runs containers using the Docker Engine, a lightweight runtime and tooling set.

Here’s how it works:

Dockerfile β†’ describes the environment

Docker Image β†’ built from Dockerfile

Docker Container β†’ running instance of the image
Enter fullscreen mode Exit fullscreen mode

πŸ› οΈ Installing Docker
On Windows / macOS:

Download Docker Desktop: https://www.docker.com/products/docker-desktop

Follow the installation instructions.

Verify with:

docker --version
Enter fullscreen mode Exit fullscreen mode

On Linux (Ubuntu):

sudo apt update
sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker

πŸ“ Key Docker Concepts
🧱 1. Dockerfile

A script with instructions to build Docker images.

Example:

Use an official Python runtime

FROM python:3.10

Set working directory

WORKDIR /app

Copy source code

COPY . .

Install dependencies

RUN pip install -r requirements.txt

Command to run

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

πŸ“Έ 2. Docker Image

An immutable snapshot built from a Dockerfile.

Build:

docker build -t my-python-app .

πŸ“¦ 3. Docker Container

A running instance of a Docker image.

Run:

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

πŸ” Docker CLI Cheatsheet

List containers

docker ps -a

Stop container

docker stop

Remove container

docker rm

List images

docker images

Remove image

docker rmi

Start shell in a container

docker exec -it /bin/bash

πŸš€ Practical Example: Python Flask App in Docker
File Structure:

.
β”œβ”€β”€ app.py
β”œβ”€β”€ requirements.txt
└── Dockerfile

app.py

from flask import Flask
app = Flask(name)

@app.route('/')
def home():
return "Hello from Docker!"

if name == 'main':
app.run(host='0.0.0.0', port=5000)

requirements.txt

flask

Dockerfile

(See earlier example)

Build and Run:

docker build -t flask-app .
docker run -d -p 5000:5000 flask-app

Visit: http://localhost:5000
🧠 Docker Best Practices

Use .dockerignore to exclude files from the image

Minimize layers in your Dockerfile

Use multi-stage builds for smaller images

Keep containers stateless

Use volumes for persistent data
Enter fullscreen mode Exit fullscreen mode

🧰 Bonus: Docker Compose

For multi-container applications:
docker-compose.yml

version: '3'
services:
web:
build: .
ports:
- "5000:5000"

Run it:

docker-compose up --build

Top comments (0)