Getting started with Docker: complete step-by-step guide
Learn how to get started with Docker: installation, containers, images, Dockerfile and practical examples for modern development.
Learn how to get started with Docker: installation, containers, images, Dockerfile and practical examples for modern development.
Docker has become a standard tool in modern software development. It allows you to build consistent, portable and reproducible environments, eliminating the classic “it works on my machine” problem.
In this guide you will learn how to get started with Docker from scratch, from installation to running your first containers and building custom images.
Docker is a platform that lets you package applications and dependencies into containers, which are lightweight and isolated runtime environments.
Docker is widely used in CI/CD pipelines, microservices architectures and cloud-native systems.
The easiest way is Docker Desktop, which includes everything you need.
Docker Desktop runs Docker Engine inside a lightweight virtual machine.
sudo apt update
sudo apt install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo tee /etc/apt/keyrings/docker.asc > /dev/null
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \
https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo $VERSION_CODENAME) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io
Verify installation:
docker --version
Let’s start with a simple official image:
docker run -d -p 8080:80 nginx
Open http://localhost:8080 in your browser.
Docker automatically pulls the image if it is not available locally.
Check running containers:
docker ps
docker images docker ps -a
A Dockerfile defines how to build a custom image.
FROM node:18-alpine WORKDIR /app COPY package*.json ./ RUN npm install COPY . . EXPOSE 3000 CMD ["npm", "start"]
Build the image:
docker build -t node-app:1.0 .
Run it:
docker run -p 3000:3000 node-app:1.0
Never store secrets or credentials inside Docker images.
Docker Compose allows you to manage multiple services easily.
version: '3.8'
services:
app:
build: .
ports:
- "3000:3000"
depends_on:
- db
db:
image: postgres:15
environment:
POSTGRES_PASSWORD: example
Start everything with:
docker-compose up -d
.dockerignorelatestDocker is a core skill for modern developers. By mastering the basics, you can build scalable, reliable and portable applications with confidence.
Useful Resources: