Introduction
Docker has become one of the most popular technologies for deploying and managing applications in modern server environments. By packaging applications and their dependencies into isolated containers, Docker provides consistency across development, essai, and production environments while minimizing resource consumption.
When combined with a Serveur privé virtuel (VPS), Docker offers a powerful, flexible, and cost-effective platform for hosting websites, Apis, bases de données, environnements de développement, and microservices.
This guide explains what Docker is, why it is beneficial for VPS hosting, and how to install and configure Docker on an Ubuntu VPS.
What Is Docker?
Docker is an open-source containerization platform that allows applications to run inside isolated environments known as containers.
Unlike traditional virtual machines, Docker containers do not require a separate operating system. Plutôt, containers share the host operating system kernel while maintaining isolation between applications.
This architecture provides several advantages:
Hébergement Web WordPress
À partir de 3,99 $/mois
- Lower resource usage
- Faster deployment
- Consistent environments
- Simplified application management
- Évolutivité améliorée
How Docker Works
Docker uses several key components:
Images
Docker images serve as templates used to create containers.
An image contains:
- Application code
- Runtime environment
- Libraries
- Dependencies
- Configuration files
Images are immutable and reusable.
Conteneurs
Containers are running instances of Docker images.
Multiple containers can run simultaneously on the same VPS without interfering with each other.
Serveur VPS pas cher
À partir de 2,99 $/mois
Dockerfile
A Dockerfile is a text file containing instructions used to build Docker images automatically.
Exemple:
FROM ubuntu:24.04
RUN apt update && apt install -y nginx
CMD ["nginx", "-g", "daemon off;"]
Docker Registry
Docker registries store and distribute Docker images.
Popular registries include:
- Docker Hub
- GitHub Container Registry
- Quay.io
- Private Registries
Why Use Docker on a VPS?
Docker and VPS hosting work exceptionally well together.
Resource Efficiency
Containers consume significantly fewer resources than traditional virtual machines because they share the host operating system kernel.
Hébergement VPS Windows
Accès à distance et administrateur complet
Les avantages incluent:
- Lower memory usage
- Reduced CPU overhead
- Faster startup times
Application Isolation
Each application runs inside its own container.
This prevents:
- Dependency conflicts
- Package version conflicts
- Application interference
Portabilité
Using the same image improves consistency, but architecture, kernel features, storage and configuration can still change behavior.
You can build a container on your development machine and deploy the exact same container to production.
Évolutivité
Containers can be replicated quickly to handle increased traffic or workloads.
This is particularly useful for:
- Apis
- SaaS applications
- Web applications
- Microservices
Simplified Deployment
Applications can be deployed with a single command rather than manually installing software and dependencies.
Common Docker VPS Use Cases
Docker is widely used for:
Website Hosting
Exemples:
- WordPress
- Joomla
- Drupal
- Laravel
Development Environments
Developers can maintain isolated environments for:
- PHP
- Python
- Node.js
- Go
- Java
Databases
Popular database containers include:
- MySQL
- MariaDB
- PostgreSQL
- MongoDB
- Redis
Reverse Proxies
Exemples:
- Nginx
- Traefik
- HAProxy
Self-Hosted Applications
Exemples:
- Nextcloud
- Mastodon
- Open WebUI
- LibreChat
- GitLab
Conditions préalables
These commands target a fresh, supported Ubuntu VPS. If Docker or containerd is already installed, review package conflicts and preserve existing workloads before changing repositories. Run Docker commands with sudo until you deliberately grant Docker-group access.
Before installing Docker, ensure your VPS meets the following requirements.
Operating System
Recommended:
- Ubuntu 22.04 LTS
- Ubuntu 24.04 LTS
Other distributions require their own installation instructions; examples include:
- AlmaLinux
- Linux rocheux
- Debian
- Feutre
Root or Sudo Access
Verify access:
sudo whoami
Expected output:
root
Update Existing Packages
Update the operating system before installation:
sudo apt update
sudo apt upgrade -y
Installing Docker on Ubuntu
Étape 1: Install Required Dependencies
Install prerequisite packages:
sudo apt install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common \
gnupg \
lsb-release -y
Étape 2: Add Docker’s Official GPG Key
Download and install the Docker repository signing key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
Vérifier:
ls -l /usr/share/keyrings/docker.gpg
Étape 3: Add Docker Repository
Add Docker’s official repository:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Update package lists:
sudo apt update
Étape 4: Install Docker Engine
Install Docker:
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Étape 5: Verify Docker Installation
Check Docker version:
docker --version
Example output:
Docker version <installed-version>
Verify service status:
sudo systemctl status docker
Expected output:
active (running)
Étape 6: Enable Docker at Boot
Enable automatic startup:
sudo systemctl enable docker
Vérifier:
sudo systemctl is-enabled docker
Expected output:
enabled
Running Your First Docker Container
Docker provides a simple test image.
Courir:
sudo docker run --rm hello-world
Successful output confirms:
- Docker Engine is working
- Container downloads function correctly
- Network connectivity is operational
Running an Nginx Container
Launch a web server:
docker run -d \
--name nginx \
-p 80:80 \
nginx
Verify running containers:
docker ps
Open your browser:
http://SERVER-IP
The Nginx welcome page should appear.
Running Docker Without Root
Membership in the docker group effectively grants root-level control of this server; only trusted administrators should receive it. This is different from Docker rootless mode.
Par défaut, Docker requires root privileges.
Add your user to the Docker group:
sudo usermod -aG docker $USER
Apply changes:
newgrp docker
Vérifier:
docker ps
If no sudo is required, configuration is successful.
Basic Docker Commands
List Running Containers
docker ps
List All Containers
docker ps -a
View Images
docker images
Stop Container
docker stop container_name
Start Container
docker start container_name
Restart Container
docker restart container_name
Remove Container
docker rm container_name
Remove Image
docker rmi image_name
Installing Docker Compose
Modern Docker installations include Docker Compose as a plugin.
Vérifier:
docker compose version
Example output:
Docker Compose version v2.x.x
Creating Your First Docker Compose Project
Remove the earlier demonstration NGINX container first if it still uses port 80 or the name nginx. For real applications, use persistent volumes, versioned image tags and tested sauvegardes before replacing containers.
Create a project directory:
mkdir docker-test
cd docker-test
Create:
nano compose.yml
Exemple:
services:
nginx:
image: nginx
container_name: nginx
ports:
- "80:80"
Start:
docker compose up -d
Vérifier:
docker compose ps
Stop:
docker compose down
Managing Container Logs
View logs:
docker logs container_name
Follow logs in real time:
docker logs -f container_name
This is particularly useful when troubleshooting applications.
Updating Docker Containers
Pull latest image:
docker pull nginx
Stop container:
docker stop nginx
Remove container:
docker rm nginx
Create new container using the updated image.
Docker Security Best Practices
Published ports can bypass normal UFW filtering because Docker manages its own network rules. Restrict access using Docker-compatible filtering or an upstream firewall and bind private services to localhost or a protected interface. Never expose the unauthenticated Docker API.
Use Trusted Images
Prefer official images from trusted registries.
Exemple:
nginx
mariadb
redis
ubuntu
Avoid Running as Root
Configure applications to run as non-root users whenever possible.
Keep Docker Updated
Update regularly:
sudo apt update
sudo apt upgrade
Limit Resource Usage
Exemple:
docker run \
--memory=512m \
--cpus=1 \
nginx
This prevents a container from consuming excessive resources.
Remove Unused Objects
Cleanup unused resources:
docker system prune -a
Review carefully before confirming.
Common Docker Troubleshooting
Docker Service Not Running
Start manually:
sudo systemctl start docker
Permission Denied
Verify group membership:
groups
Assurer:
docker
appears in the output.
Port Already in Use
Check listening services:
ss -tulpn
Modify Docker port mapping if necessary:
docker run -p 8080:80 nginx
Container Exits Immediately
Inspect logs:
docker logs container_name
Most startup issues can be identified through log analysis.
Docker vs Virtual Machines
| Fonctionnalité | Docker Containers | Virtual Machines |
|---|---|---|
| Startup Time | Seconds | Minutes |
| Utilisation des ressources | Faible | Haut |
| Guest OS | Not Required | Required |
| Performance | Near Native | Slight Overhead |
| Évolutivité | Excellent | Modéré |
Containers are ideal for application deployment, while virtual machines remain useful when complete operating system isolation is required.
Pensées finales
Docker transforms a VPS into a flexible application hosting platform capable of running websites, Apis, bases de données, environnements de développement, and enterprise applications with minimal overhead. Its lightweight architecture, portability, and scalability make it one of the most valuable tools available to modern system administrators and developers.
By installing Docker on your VPS and learning the basics of container management, you gain a powerful foundation for deploying reliable, sécurisé, and highly portable applications across virtually any environment.
