Docker lets you run applications in isolated containers - making deployments reproducible, portable, and easy to manage. This guide covers installing Docker and getting started with containers on Ubuntu 22.04. See VPS prices.
What Is Docker?
Docker packages an application and all its dependencies into a container - a lightweight, isolated environment that runs consistently regardless of the underlying server. Instead of installing and configuring software manually, you pull a container image and run it.
Benefits:
- Deploy apps in seconds
- No dependency conflicts between apps
- Easy to update, restart, or roll back
- Same container runs on any Docker-compatible server
Step 1: Install Docker
curl -fsSL https://get.docker.com | sh
This official install script handles everything automatically.
Verify the installation:
docker --version
docker run hello-world
Step 2: Install Docker Compose
Docker Compose lets you define and run multi-container apps with a single file.
apt install docker-compose-plugin -y
docker compose version
Step 3: Run Your First Container
Example: Run Nginx in Docker
docker run -d -p 80:80 --name my-nginx nginx
-d- run in background (detached)-p 80:80- map port 80 on the host to port 80 in the container--name my-nginx- give it a friendly namenginx- the Docker image to use
Visit http://YOUR_SERVER_IP - you'll see the Nginx welcome page.
Stop and Remove the Container
docker stop my-nginx
docker rm my-nginx
Step 4: Use Docker Compose for Multi-Container Apps
Docker Compose is the standard way to run apps with multiple services (e.g. a web app + database).
Example: WordPress + MySQL
Create a directory and a docker-compose.yml file:
mkdir ~/wordpress && cd ~/wordpress
nano docker-compose.yml
version: '3.8'
services:
db:
image: mysql:8.0
restart: always
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: wordpress
MYSQL_USER: wpuser
MYSQL_PASSWORD: wppassword
volumes:
- db_data:/var/lib/mysql
wordpress:
image: wordpress:latest
restart: always
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_USER: wpuser
WORDPRESS_DB_PASSWORD: wppassword
volumes:
- wp_data:/var/www/html
depends_on:
- db
volumes:
db_data:
wp_data:
Start it:
docker compose up -d
Visit http://YOUR_SERVER_IP:8080 to complete WordPress setup.
Stop it:
docker compose down
Common Docker Commands
| Command | Description |
|---|---|
docker ps |
List running containers |
docker ps -a |
List all containers (including stopped) |
docker images |
List downloaded images |
docker logs container-name |
View container logs |
docker exec -it container-name bash |
Open shell inside container |
docker stop container-name |
Stop a running container |
docker rm container-name |
Remove a stopped container |
docker pull image-name |
Download an image |
docker rmi image-name |
Remove an image |
docker system prune |
Clean up unused containers, images, networks |
Step 5: Persist Data with Volumes
By default, data inside containers is lost when the container is removed. Use volumes to persist data:
docker run -d \
-p 80:80 \
-v /home/yourname/nginx-html:/usr/share/nginx/html \
--name my-nginx nginx
Now your HTML files from /home/yourname/nginx-html are served by Nginx
inside the container.
Step 6: Configure Nginx as a Reverse Proxy for Docker Apps
Run your app container on a local port (e.g. 8080) and let Nginx handle public traffic:
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Then add SSL with Certbot as usual.
Popular Docker Images to Explore
| App | Docker Image |
|---|---|
| Nginx | nginx |
| WordPress | wordpress |
| MySQL | mysql |
| Nextcloud | nextcloud |
| Portainer (Docker GUI) | portainer/portainer-ce |
| Gitea (self-hosted Git) | gitea/gitea |
| Uptime Kuma (monitoring) | louislam/uptime-kuma |
Questions? Email us at [email protected] - we reply in under 2 hours, 7 days a week.