How to Install and Use Docker on Linux
Docker has revolutionized the way developers build, ship, and run applications by leveraging containerization. For Linux users, Docker offers an efficient and scalable way to manage applications. This article will guide you through the installation and usage of Docker on Linux, enabling you to harness its full potential.
Prerequisites
Before installing Docker, ensure your Linux system meets the following requirements:
- A 64-bit operating system.
- Kernel version 3.10 or higher.
- Root or sudo privileges.
To check your kernel version, run:
uname -r
Step by step
Step 1: Update Your System
Ensure your package manager is up to date to avoid conflicts during installation:
sudo apt update && sudo apt upgrade -y
Step 2: Install Docker
On Ubuntu:
Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Set up the Docker repository:
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
Install Docker:
sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io -y
On CentOS:
Remove older Docker versions:
sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
Set up the repository:
sudo yum install -y yum-utils sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Install Docker:
sudo yum install docker-ce docker-ce-cli containerd.io -y
Step 3: Start and Enable Docker
After installation, start the Docker service and ensure it runs on startup:
sudo systemctl start docker
sudo systemctl enable docker
Verify that Docker is running:
sudo systemctl status docker
Step 4: Test Docker Installation
Run the following command to verify Docker is working correctly:
sudo docker run hello-world
If Docker is installed correctly, you will see a message indicating that the installation is successful.
Basic Docker Commands
Here are some essential Docker commands to get you started:
Check Docker version:
docker --version
List running containers:
docker ps
List all containers:
docker ps -a
Pull an image:
docker pull [image_name]
Stop a container:
docker stop [container_id]
Remove a container:
docker rm [container_id]
FAQs
What are the system requirements for installing Docker on Linux? Docker requires a 64-bit OS, a kernel version of 3.10 or higher, and root or sudo access.
How do I verify that Docker is running on my Linux system? Use the command
sudo systemctl status docker
or runsudo docker run hello-world
to ensure Docker is working correctly.Can I install Docker on all Linux distributions? Docker supports most major Linux distributions, including Ubuntu, CentOS, Debian, Fedora, and more. Check the official Docker documentation for compatibility.
Conclusion
Installing and using Docker on Linux is a straightforward process that unlocks powerful capabilities for developers and system administrators. Whether you’re managing applications or building CI/CD pipelines, Docker offers unmatched efficiency and scalability.