Getting Started with Docker: A Complete Guide
Table of Contents
• Getting Started with Docker: A Complete Guide
Getting Started with Docker: A Complete Guide
Docker has transformed how we deploy and manage applications. Whether you are running a single homelab service or orchestrating a complex microservices architecture, understanding Docker is essential for modern infrastructure.
In this guide, we will cover everything you need to know to go from zero to productive with Docker containers.
What is Docker?
Docker is a platform for developing, shipping, and running applications in containers. Unlike traditional virtual machines, containers share the host OS kernel and are lightweight. A container might start in seconds while a VM takes minutes.
The key benefits include consistency across environments, isolation between services, efficient resource usage, and rapid deployment.
Core Concepts
Images are read-only templates that define what goes into a container. You build images from a Dockerfile, which specifies the base image, dependencies, and commands to run.
Containers are running instances of images. Multiple containers can run from the same image, each isolated from the others.
Volumes persist data outside the container lifecycle. When a container is deleted, data in volumes survives. This is critical for databases and stateful services.
Networks allow containers to communicate. By default, containers on the same network can reach each other by hostname.
Installation
On Ubuntu, install Docker with:
curl -fsSL https://get.docker.com | sh
After installation, add your user to the docker group to avoid needing sudo:
sudo usermod -aG docker $USER
Verify the installation by running: docker run hello-world
Your First Container
To run Nginx in a container: docker run -d -p 8080:80 --name web nginx
The -d flag runs in detached mode. -p 8080:80 maps host port 8080 to container port 80. --name gives the container a memorable name.
Visit http://localhost:8080 to see Nginx running.
Managing Containers
docker ps shows running containers. docker ps -a includes stopped ones.
docker stop web stops the container. docker start web starts it again.
docker logs web shows the container output. docker exec -it web sh opens a shell inside the running container.
docker rm web removes the container. Use docker rmi nginx to remove the image.
Docker Compose
For multi-container applications, Docker Compose is essential. A docker-compose.yml file defines services, networks, and volumes.
Example for a WordPress site:
version: '3'services: db: image: mysql:8 volumes: - db_data:/var/lib/mysql environment: MYSQL_ROOT_PASSWORD: secret wordpress: image: wordpress ports: - "8080:80" environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_PASSWORD: secretvolumes: db_data:
Run docker-compose up -d to start everything. docker-compose down stops and removes the containers.
Best Practices
Use official images as bases when possible. Specify version tags to avoid unexpected updates.
Minimize image size by using Alpine-based images or multi-stage builds. Smaller images are faster to pull and more secure.
Never store secrets in Dockerfiles. Use environment variables or Docker secrets for sensitive data.
Use healthchecks to let Docker know when a container is ready. This helps with service discovery and orchestration.
Homelab Applications
Common homelab uses for Docker include media servers (Plex, Jellyfin, Sonarr, Radarr), home automation (Home Assistant), monitoring (Prometheus, Grafana), and development environments.
We run most of our services as Docker containers on our Proxmox cluster, with Docker Compose files version-controlled in Git.
Comments
Join the discussion on "Getting Started with Docker: A Complete Guide"