Getting Started with Docker: A Practical Guide for Beginners

Leader posted Originally published at dev.to 2 min read

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

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

Installing Docker

On Windows / macOS:

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

Follow the installation instructions.

Verify with:

docker --version
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

Bonus: Docker Compose

For multi-container applications:

docker-compose.yml

version: '3'
services:
web:
build: .
ports:

  • "5000:5000"

Run it:

docker-compose up --build

If you read this far, tweet to the author to show them you care. Tweet a Thanks
0 votes
0 votes

More Posts

Docker Security Best Practices: A Practical Guide for Developers

CliffordIsaboke - Jul 7

A Beginner's Guide to Docker: Dockerizing Your Application for Easy Deployment

Anadudev - Feb 13

Understanding Docker-Compose and Environmental Variables: A Beginner's Guide

Anadudev - Feb 23

Containerized Java: Fix Version Compatibility with Docker

Aditya Pratap Bhuyan - Jun 26

Beginner’s Guide to Environment Variables with Docker

Kilama Elie - Aug 20
chevron_left