Learn Docker Basics
Learn Docker Basics
If Linux is the foundation of your home server, Docker is the construction crew.
Before Docker, installing server software was genuinely hard. Every application had its own installation process, its own dependencies, its own configuration quirks — and they frequently conflicted with each other. Getting three apps running on the same server was a project that could take days.
Docker changed all of that. Today, installing a complex application like Nextcloud or Immich takes about five minutes and a single file.
What Is Docker?
Docker is a tool that runs software in isolated containers.
Think of a container like a shipping container. A physical shipping container can hold any cargo — electronics, furniture, food — and it can be loaded onto any ship, truck, or train. The contents don’t care what’s carrying them. The carrier doesn’t care what’s inside.
Docker containers work the same way. Each container holds an application and everything it needs to run: the right version of every library, every dependency, every configuration file. The container runs on your Linux server without interfering with anything else.
This means:
- You don’t install software directly on your server anymore — you run containers
- Applications can’t conflict with each other because they’re isolated
- Installing an app is just a matter of describing what container you want to run
- Removing an app is as simple as stopping and deleting its container
Docker Compose
Docker Compose is the tool you’ll use to actually manage your containers. Instead of typing long commands to start each container, you describe your entire setup in a simple text file called docker-compose.yml.
Here’s what a minimal Docker Compose file looks like:
services:
whoami:
image: traefik/whoami
ports:
- "8080:80"
restart: unless-stopped
This file says: run a container using the traefik/whoami image, make it accessible on port 8080, and restart it automatically if it ever stops.
That’s the pattern for every application you’ll install this weekend. The details change — different images, different ports, different settings — but the structure is always the same.
Install Docker
SSH into your server and run the following commands. These are the official Docker installation steps for Ubuntu:
# Remove any old versions
sudo apt remove docker docker-engine docker.io containerd runc
# Install required packages
sudo apt install -y ca-certificates curl gnupg
# Add Docker's official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Add Docker's repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
When that finishes, run one more command to add your user to the Docker group — this lets you run Docker commands without typing sudo every time:
sudo usermod -aG docker $USER
Log out and back in for this change to take effect:
exit
Then reconnect via SSH. Now verify Docker is working:
docker run hello-world
You should see a message that says “Hello from Docker!” — that means Docker is installed and working correctly.
Set Up Your Folder Structure
Before you start installing apps, create a consistent folder structure for your Docker projects. This keeps things organized and makes management much easier.
mkdir -p ~/docker/{immich,nextcloud,jellyfin,vaultwarden,paperless}
This creates a docker folder in your home directory with a subfolder for each application. Each app will live in its own folder with its own docker-compose.yml file and configuration.
Understanding the Key Concepts
Before we start launching services, here are the four concepts you’ll encounter repeatedly:
Image — A pre-built package containing an application and everything it needs. Images are downloaded from Docker Hub (hub.docker.com), which is like an app store for containers. When you see something like image: immich-app/immich-server, that’s pointing to an image on Docker Hub.
Container — A running instance of an image. The image is the blueprint; the container is the building. You can run multiple containers from the same image.
Volume — Where your data lives. By default, data inside a container disappears when the container stops. Volumes map a folder on your server to a folder inside the container, so your data persists. This is how your photos stay around even when Immich restarts.
Port — How you access an application from your browser. When you see "8080:80", it means port 8080 on your server maps to port 80 inside the container. You’d access the app at http://your-server-ip:8080.
Essential Docker Commands
You’ll use these commands constantly. Bookmark this page.
| Command | What it does |
|---|---|
docker compose up -d |
Start all services defined in docker-compose.yml |
docker compose down |
Stop all services |
docker compose pull |
Download newer versions of your images |
docker compose logs -f |
Watch live logs from your containers |
docker ps |
List all running containers |
docker ps -a |
List all containers including stopped ones |
docker restart containername |
Restart a specific container |
All of these commands are run from inside the folder containing your docker-compose.yml file. So if you’re working with Nextcloud, you’d cd ~/docker/nextcloud first, then run the command.
Your First Test
Let’s run a real container to make sure everything is working. This one runs a simple web interface for managing your Docker containers:
cd ~/docker
mkdir portainer && cd portainer
Create a file called docker-compose.yml:
nano docker-compose.yml
Paste this content:
services:
portainer:
image: portainer/portainer-ce:latest
ports:
- "9000:9000"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer_data:/data
restart: unless-stopped
volumes:
portainer_data:
Save and exit nano with Ctrl+X, then Y, then Enter.
Start the container:
docker compose up -d
Docker will download the Portainer image and start the container. Open a browser on your main computer and go to:
http://your-server-ip:9000
You should see the Portainer setup screen. Create an admin username and password. Portainer gives you a visual dashboard for all your Docker containers — useful for checking status, reading logs, and managing services without memorizing every command.
What You’ve Built
At this point you have:
- Docker and Docker Compose installed and working
- A clean folder structure ready for each application
- Portainer running as a management dashboard
- A solid understanding of Docker’s core concepts
The foundation is complete. Time to start launching services.
Cactus Commons Media