GICT knowledge base
How to Install Docker on Ubuntu 24.04 LTS
Published
Docker is a platform that bundles applications with all their required components into compact, portable containers. Unlike virtual machines, these containers use the host system’s operating system kernel, which makes them quicker to start and more resource-friendly.
Key benefits of Docker include:
- Consistency across environments: Applications run identically on development, testing, and production systems
- Resource efficiency: Containers are lightweight and don’t need an entire operating system to run, so they consume much less memory and CPU compared to virtual machines.
- Rapid deployment: Since containers are small and self-contained, you can launch applications in just a few seconds instead of waiting minutes like traditional setups.
- Easy scaling: Scale applications up or down based on demand
- Isolated environments: Run multiple applications without conflicts
System Requirements
Before installing Docker on Ubuntu 24.04, ensure your system meets these requirements:
- Ubuntu 24.04 LTS (64-bit)
- Minimum 4GB RAM (8GB recommended)
- At least 20GB free disk space
- User account with sudo privileges
- Active internet connection
Verify your Ubuntu version:
lsb_release -a
Installation Method 1: Official Docker Repository (Recommended)
This method uses Docker’s official repository to install the software, so you’ll always get the most up-to-date stable version along with important security updates.
Step 1: Update System Packages
Start by updating your package manager and upgrading existing packages:
sudo apt update
sudo apt upgrade -y
Step 2: Install Prerequisites
Install required packages for adding external repositories over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
These packages enable:
- apt-transport-https: HTTPS support for package manager
- ca-certificates: Certificate authority certificates
- curl: Command-line tool for downloading files
- software-properties-common: Scripts for managing software repositories
Step 3: Add Docker’s GPG Key
Download and add Docker’s official GPG key to verify packages:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Step 4: Add Docker Repository
Add Docker’s stable repository to your system:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Step 5: Update Package Index
Refresh the package list to include Docker packages:
sudo apt update
Step 6: Install Docker Engine
Install Docker Engine and related components:
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
This command installs:
- docker-ce: Docker Community Edition engine
- docker-ce-cli: Command-line interface
- containerd.io: Container runtime
- docker-buildx-plugin: Extended build capabilities
- docker-compose-plugin: Multi-container application management
Installation Method 2: Convenience Script
Docker provides an automated installation script. While convenient, this method is not recommended for production environments due to security considerations.
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
rm get-docker.sh
Post-Installation Setup
Enable and Start Docker Service
Configure Docker to start automatically on system boot:
sudo systemctl enable docker
sudo systemctl start docker
Check service status:
sudo systemctl status docker
Configure User Permissions
Add your user to the Docker group to use Docker without typing sudo every time:
sudo usermod -aG docker $USER
Apply group changes by logging out and back in, or use:
newgrp docker
Verify Installation
Test Docker installation with these commands:
docker --version
docker info
Run the hello-world container to check if Docker is set up properly.
docker run hello-world
A successful installation will display the “Hello from Docker!” message.
Essential Docker Commands
Here are fundamental Docker commands every user should know:
Container Management:
# List running containers
docker ps
# List all containers
docker ps -a
# Start a container
docker start container_name
# Stop a container
docker stop container_name
# Remove a container
docker rm container_name
Image Management:
# List local images
docker images
# Pull an image from registry
docker pull image_name
# Remove an image
docker rmi image_name
# Build image from Dockerfile
docker build -t image_name .
Running Containers:
# Run container interactively
docker run -it ubuntu bash
# Run container in background
docker run -d nginx
# Run container with port mapping
docker run -p 8080:80 nginx
Common Configuration Tasks
Configure Docker Daemon
Create or Edit the Docker daemon config file:
sudo mkdir -p /etc/docker
sudo nano /etc/docker/daemon.json
Example configuration:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"storage-driver": "overlay2"
}
Restart Docker after configuration changes:
sudo systemctl restart docker
Set Up Docker Compose
Docker Compose is included with the docker-compose-plugin. Verify installation:
docker compose version
Troubleshooting Common Issues
Permission Denied Errors
If you encounter permission errors after adding user to docker group:
- Log out and log back in
- Restart the Docker service:
sudo systemctl restart docker - Verify group membership:
groups $USER
Docker Service Won’t Start
Check Docker service status and logs:
sudo systemctl status docker
sudo journalctl -u docker
Common solutions:
- Restart the docker service:
sudo systemctl restart docker - Check disk space:
df -h - Verify configuration file syntax
Storage Issues
Docker stores data in /var/lib/docker/. Monitor disk usage:
docker system df
Clean up unused resources:
docker system prune -a
Security Best Practices
Implement these security measures for production environments:
- Keep Docker Updated:
sudo apt updatesudo apt upgrade docker-ce docker-ce-cli containerd.io - Use Official Images:
Pull images from official repositories
Verify image signatures when possible
Scan images for vulnerabilities - Limit Container Privileges:
Avoid running containers as root
Use user namespaces
Implement resource limits - Network Security:
Use custom bridge networks
Limit port exposure
Implement proper firewall rules
Performance Optimization
Storage Driver Configuration
Ubuntu 24.04 uses an overlay2 storage driver by default, which offers optimal performance. Verify current driver:
docker info | grep "Storage Driver"
Resource Limits
Set container resource limits to prevent resource exhaustion:
# Limit memory and CPU
docker run -m 512m --cpus="1.0" nginx
Image Optimization
- Use multi-stage builds
- Minimize image layers
- Use appropriate base images
- Remove unnecessary packages
Uninstalling Docker
If you need to completely remove Docker:
Step 1: Stop Docker service
sudo systemctl stop docker
Step 2: Remove Docker packages
sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 3: Remove Docker data
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
Step 4: Remove repository
sudo rm /etc/apt/sources.list.d/docker.list
sudo rm /usr/share/keyrings/docker-archive-keyring.gpg
Next Steps
After successfully installing Docker, consider exploring these advanced topics:
- Container Orchestration:
- Docker Swarm for clustering
- Kubernetes integration
- Container networking
- Development Workflow:
- Creating custom Dockerfiles
- Multi-container applications with Docker Compose
- CI/CD pipeline integration
- Monitoring and Logging:
- Container health checks
- Log aggregation
- Performance monitoring
Conclusion
Installing Docker on Ubuntu 24.04 LTS is simple and reliable when you use the official Docker repository. This approach ensures you receive regular security updates and access to the latest features. The installation process typically takes 10-15 minutes and provides a solid foundation for containerized application development and deployment.
Docker transforms how applications are built, shipped, and run. Whether you’re developing microservices, testing applications in isolated environments, or deploying scalable web applications, Docker provides the tools and flexibility needed for modern software development.
Start with basic container operations, gradually progress to more complex scenarios like multi-container applications, and eventually explore orchestration platforms for production deployments. The Docker ecosystem offers extensive documentation and community support to help you master containerization technology.
Related guides
How to Restrict an SSH Key to One Command
Restrict an SSH key to one command with authorized_keys options. Protect the command and check that unwanted shell and forwarding access are denied.
Linux and CommandsSelf-Hosted Video Processing With FFmpeg: A Practical Guide
Learn how to self-host video processing on a VPS using FFmpeg, with practical commands for conversion, compression, thumbnails, and automated workflows.
Linux and CommandsHow to use nohup: Commands in Linux That Survive Terminal Closes
Keep commands running after you close the terminal. nohup examples with wget, Python, rsync, and Docker on any VPS.
Linux and CommandsHow to Fix “Too Many Open Files” Error on Linux Servers
Learn how to fix the "Too Many Open Files" error on Linux servers by understanding file descriptors, adjusting limits, and diagnosing leaks effectively.
