Docker Basics
Practical introduction to Docker images, containers, and everyday command-line workflows
created: Sat Mar 14 2026 00:00:00 GMT+0000 (Coordinated Universal Time)
updated: Sat Mar 14 2026 00:00:00 GMT+0000 (Coordinated Universal Time) #containers#docker#linux
Introduction
Docker packages applications and their dependencies into images that run as isolated containers. For homelab and developer workflows, it is commonly used to deploy repeatable services without building a full virtual machine for each workload.
Purpose
Docker is useful when you need:
- Repeatable application packaging
- Simple local development environments
- Fast service deployment on Linux hosts
- Clear separation between host OS and application runtime
Architecture Overview
Core Docker concepts:
- Image: immutable application package template
- Container: running instance of an image
- Registry: source for pulling and pushing images
- Volume: persistent storage outside the writable container layer
- Network: connectivity boundary for one or more containers
Typical flow:
Dockerfile -> Image -> Registry or local cache -> Container runtimeStep-by-Step Guide
1. Verify Docker is installed
docker version
docker info2. Pull and run a container
docker pull nginx:stable
docker run -d --name web -p 8080:80 nginx:stable3. Inspect the running container
docker ps
docker logs web
docker exec -it web sh4. Stop and remove it
docker stop web
docker rm webConfiguration Example
Run a service with a persistent named volume:
docker volume create app-data
docker run -d \
--name app \
-p 3000:3000 \
-v app-data:/var/lib/app \
ghcr.io/example/app:latestInspect resource usage:
docker statsTroubleshooting Tips
Container starts and exits immediately
- Check
docker logs <container> - Verify the image's default command is valid
- Confirm required environment variables or mounted files exist
Port publishing does not work
- Verify the service is listening inside the container
- Confirm the host port is not already in use
- Check host firewall rules
Data disappears after recreation
- Use a named volume or bind mount instead of the writable container layer
- Confirm the application writes data to the mounted path
Best Practices
- Pin images to a known tag and update intentionally
- Use named volumes for application state
- Prefer non-root containers when supported by the image
- Keep containers single-purpose and externalize configuration
- Use Compose for multi-service stacks instead of long
docker runcommands