Docker simplifies application deployment with containerization. Running Docker without root enhances security and streamlines workflows. This guide will walk you through installing Docker on Linux and configuring it for non-root usage.
Prerequisites
- A Linux system (Ubuntu, Debian, CentOS, etc.)
- A user account with
sudoprivileges.
1. Update Your System
Keeping your system updated ensures compatibility and security.
For Ubuntu/Debian:
sudo apt update && sudo apt upgrade -y
For RHEL-based systems (e.g., CentOS):
sudo yum update -y
2. Install Docker
Docker installation steps vary slightly between Linux distributions.
For Ubuntu/Debian
-
Install prerequisite packages:
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common -
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 -y docker-ce docker-ce-cli containerd.io
For RHEL/CentOS
-
Install prerequisite packages:
sudo yum install -y yum-utils -
Set up the Docker repository:
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo -
Install Docker:
sudo yum install -y docker-ce docker-ce-cli containerd.io
3. Start and Enable Docker
Start the Docker service:
sudo systemctl start docker
Enable Docker to start on boot:
sudo systemctl enable docker
4. Verify Docker Installation
Run a test to confirm Docker is installed correctly:
sudo docker run hello-world
You should see a message indicating Docker is running successfully.
5. Configure Docker for Non-Root Usage
To run Docker commands without sudo, follow these steps:
-
Add your user to the Docker group:
sudo usermod -aG docker $USER -
Log out and log back in for the group changes to apply.
-
Verify non-root access:
docker run hello-world
If the command runs successfully, Docker is now configured for non-root usage.
Additional Tips
-
Check Docker Version:
docker --version -
Manage Docker as a Service:
- Restart Docker:
sudo systemctl restart docker - Stop Docker:
sudo systemctl stop docker
- Restart Docker:
-
Uninstall Docker (if needed): For Ubuntu/Debian:
sudo apt remove -y docker-ce docker-ce-cli containerd.ioFor RHEL/CentOS:
sudo yum remove -y docker-ce docker-ce-cli containerd.io
Conclusion
Congratulations! Docker is now installed on your Linux system and can be used without root privileges. Enjoy secure and efficient containerized application development! 🚀
For more tutorials and guides, stay tuned to this blog. Have questions? Drop them in the comments below!