Docker is a powerful platform for developing, shipping, and running applications in containers. This guide will walk you through the process of installing Docker on your Virtual Private Server (VPS).
Prerequisites
- A VPS running a Linux distribution (Ubuntu/Debian recommended)
- Root or sudo access to your server
- Basic command line knowledge
Installation Steps
Step 1: Update the Package Index
First, ensure your package index is up to date:
sudo apt update
Step 2: Install Required Dependencies
Install packages needed to use repositories over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Step 3: Add Docker's Official GPG Key
Add Docker's official GPG key to ensure package authenticity:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Step 4: Set Up the Docker Repository
Add the Docker repository to your system:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Step 5: Update Package Index Again
Update the package index with the new Docker repository:
sudo apt update
Step 6: Install Docker
Install the Docker engine:
sudo apt install docker-ce
Step 7: Start and Enable Docker
Start the Docker service and enable it to start on boot:
sudo systemctl enable docker --now
Verification
Verify Docker Installation
Check Docker version:
sudo docker --version
Check Docker service status:
sudo systemctl status docker
Post-Installation Steps
Add User to Docker Group (Optional)
To use Docker without sudo:
sudo usermod -aG docker $USER
Note: Log out and back in for this change to take effect.
Managing Docker Containers
View Running Containers
List currently running containers:
docker ps
View All Containers
List all containers (including stopped ones):
docker ps -a
Troubleshooting Tips
-
If Docker fails to start, check system logs:
sudo journalctl -u docker
-
If you can't connect to Docker daemon, ensure your user is in the Docker group:
groups $USER
-
For permission denied errors, verify Docker daemon is running:
sudo systemctl status docker
Common Docker Commands
Here are some essential commands to get started:
- Pull an image:
docker pull [image-name]
- Run a container:
docker run [image-name]
- Stop a container:
docker stop [container-id]
- Remove a container:
docker rm [container-id]
- List images:
docker images
Security Considerations
- Only add trusted users to the Docker group
- Regularly update Docker to the latest version
- Use official Docker images when possible
- Regularly audit your Docker containers
Remember to periodically update Docker and your containers to ensure you have the latest security patches and features.