LibraHostDocumentation

Documentation

Complete guides for all our hosting services

🐳 Install Docker on a VPS#

Learn how to install and configure Docker and Docker Compose on your VPS to deploy your applications in containers simply and efficiently.

🎯 Objectives#

  • 🐳 Install Docker Engine on Ubuntu/Debian
  • 📦 Install Docker Compose
  • 🛠️ Master essential commands
  • 🌐 Understand networks and volumes
  • 🔧 Solve common problems

🧰 Prerequisites#

  • VPS running Ubuntu 20.04+ or Debian 11+
  • Root or sudo access
  • Active SSH connection
  • At least 2 GB RAM recommended
  • 10 GB free disk space minimum

1️⃣ System preparation#

📦 Update and cleanup#

# Complete system update sudo apt update && sudo apt upgrade -y # Remove old Docker versions (if present) for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done

2️⃣ Docker installation#

📥 Installation with official script#

# Download official installation script curl -fsSL https://get.docker.com -o get-docker.sh # Execute installation script sh get-docker.sh # Installation verification sudo systemctl status docker

✅ Installation test#

# Test with a Hello World container sudo docker run hello-world # Version verification sudo docker --version sudo docker compose version

👥 User configuration#

# Add your user to Docker group (avoids sudo) sudo usermod -aG docker $USER # Apply changes (logout/login or) newgrp docker # Test without sudo docker run hello-world

3️⃣ Docker Compose installation and usage#

📦 Docker Compose verification#

Docker Compose is now included as a plugin:

# Installation verification docker compose version # Docker Compose help docker compose --help

🚀 First practical test#

Let's test Docker with a simple web server:

# Launch an Nginx server docker run -d --name my-nginx -p 8080:80 nginx # Verify the container is working docker ps # Test in browser: http://your-ip:8080 # You should see the Nginx welcome page # Stop and remove the container docker stop my-nginx docker rm my-nginx

📝 Simple Docker Compose example#

Let's create a basic docker-compose.yml file:

# Create a test directory mkdir ~/test-docker && cd ~/test-docker # Create docker-compose.yml file cat > docker-compose.yml << 'EOF' version: "3.8" services: web: image: nginx ports: - "8080:80" EOF # Launch with Docker Compose docker compose up -d # Verification docker compose ps # Stop and cleanup docker compose down

4️⃣ Essential Docker commands#

📦 Container management#

# List active containers docker ps # List all containers (active and stopped) docker ps -a # Start a container docker start container_name # Stop a container docker stop container_name # Restart a container docker restart container_name # Remove a container docker rm container_name # Remove all stopped containers docker container prune

🖼️ Image management#

# List images docker images # Download an image docker pull nginx:latest # Remove an image docker rmi nginx:latest # Remove unused images docker image prune

📊 Monitoring and logs#

# Container logs docker logs container_name # Real-time logs docker logs -f container_name # Container statistics docker stats # Docker system information docker system info # Used disk space docker system df

🔧 Container access#

# Execute a command in a container docker exec -it container_name bash # Copy files to/from a container docker cp file.txt container_name:/path/to/destination docker cp container_name:/path/to/file.txt ./

🐙 Docker Compose commands#

# Start services docker compose up -d # View service status docker compose ps # View logs docker compose logs # Stop services docker compose down # Rebuild and start docker compose up --build -d

5️⃣ Docker networks and volumes#

🌐 Network management#

# List networks docker network ls # Create a network docker network create my-network # Connect a container to a network docker network connect my-network container_name # Inspect a network docker network inspect my-network # Remove a network docker network rm my-network

💾 Volume management#

# List volumes docker volume ls # Create a volume docker volume create my-volume # Inspect a volume docker volume inspect my-volume # Remove a volume docker volume rm my-volume # Remove unused volumes docker volume prune

6️⃣ Troubleshooting#

🔍 Common problems#

Error: "Cannot connect to Docker daemon"

# Service verification sudo systemctl status docker # Restart if necessary sudo systemctl restart docker # Permission verification groups $USER

Error: "No space left on device"

# Disk space verification df -h # Docker cleanup docker system prune -a # Check bulky logs sudo du -sh /var/lib/docker/containers/*/

Container won't start

# Log verification docker logs container_name # Configuration verification docker inspect container_name # Interactive mode test docker run -it --entrypoint /bin/bash image_name

📋 Logs and diagnostics#

# Docker daemon logs sudo journalctl -fu docker.service # Detailed system information docker system info # Real-time Docker events docker events # Detailed container inspection docker inspect container_name

✅ Installation summary#

Your Docker installation is now complete with:

  • 🐳 Docker Engine + Docker Compose installed and operational
  • 🚀 First tests completed successfully
  • 🔧 Essential commands mastered
  • 🌐 Network and volume management configured