1. What Is Docker & Why Install It on Linux?
Docker is a containerization platform enabling lightweight, isolated environments to build, ship, and run applications consistently. Since it relies on Linux kernel features like namespaces and cgroups, native Linux distributions deliver best performance, compatibility, and security.
Use Docker on Linux to:
Simplify development and deployment, identical across environments
Maximize resource efficiency, with lightweight virtualization
Leverage open-source ecosystems like Ubuntu, CentOS, Fedora, and more
2. Pre-Installation Essentials
Before installing Docker, make sure you:
Run a 64-bit, up-to-date Linux kernel
Have sudo/admin rights
On Ubuntu/Debian: add Docker’s GPG key, apt repository
On RHEL distros: enable EPEL and yum/dnf repositories
Optionally install Docker’s get.docker.com convenience script (optional)
3. Installing Docker on Ubuntu (20.04 / 22.04 / 24.04)
1. Update packages:
sudo apt update
sudo apt install \
ca-certificates \
curl \
gnupg \
lsb-release
2. Add Docker’s GPG key & stable repo:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| sudo gpg –dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
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
3. Install Docker Engine:
sudo apt update
sudo apt install docker-ce docker-ce‑cli containerd.io docker-compose-plugin
4. Verify installation:
sudo docker run hello‑world
4. Installing on CentOS / RHEL / AlmaLinux
Set up repo:
sudo dnf install -y yum-utils
sudo yum-config-manager \
–add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
Install Docker:
sudo dnf install docker-ce docker-ce-cli containerd.io
Start services:
sudo systemctl start docker
sudo systemctl enable docker
Test:
sudo docker run hello‑world
5. Installing on Fedora
Fedora is well-supported for Docker CE.
1. Add Docker repo:
sudo dnf config-manager \
–add-repo \
https://download.docker.com/linux/fedora/docker-ce.repo
2. Install packages:
sudo dnf install docker-ce docker-ce-cli containerd.io
3. Enable & verify:
sudo systemctl enable –now docker
sudo docker run hello‑world
6. Rootless Docker – Running Without Root
Most Docker setups need root. Rootless Docker enables the daemon and containers to run under a normal user, enhancing security
Steps to install:
Ensure support packages are installed (
uidmap,dbus-user-session,fuse-overlayfs)As a normal user:
curl -fsSL https://get.docker.com/rootless | shFollow script instructions to add env vars to
.bashrcor.zshrc, then enable the systemd user service:
systemctl –user enable docker
loginctl enable-linger $(whoami)- Test:
docker run hello‑world
docker run -p 8080:80 nginx
7. Running Docker Without Sudo: Docker Group
To manage Docker as a normal user (without rootless mode), add your user to the docker group:
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker # Or logout/login
docker run hello-world
8. Post-Install Configuration
Configure essential settings after installation :
Start on boot:
sudo systemctl enable docker containerd- Configure log rotation in
/etc/docker/daemon.json:
{
“log-driver”: “json-file”,
“log-opts”: {
“max-size”: “10m”,
“max-file”: “3”
}
} - User namespace mapping for security
- Proxy settings, if required
9. Security & Best Practices
Docker Host Hardening
- Use minimal Linux distros (Alpine, Fedora CoreOS)
Keep kernel & packages patched
Enable SELinux / AppArmor / Seccomp
Container Best Practices
Run as non-root inside containers (
USER appuser)Drop unnecessary Linux capabilities (
--cap-drop=ALL)Scan images regularly (Trivy, Docker Scout)
Use read-only file systems:
--read-onlyManage secrets securely (not env vars)
Rootless Mode
Suitable for developer environments
Be aware of networking and driver limitations
Podman may be a better rootless alternative
Conclusion
You now have a full-featured Docker setup on Linux:
Stable installation on Ubuntu, CentOS, Fedora
Rootless Docker for enhanced user-space security
Post-configurations to optimize usability
Security guidance for safe container operations
Group-based access via Docker group
Image placement best practices for readability
🚀 Take Action:
Deploy your first container
Apply security settings
Consider rootless or Podman for sandboxed dev work


Comments are closed