Docker – Installing on Linux
Installing Docker on Linux is one of the most common and efficient ways to run containerized applications. Linux is the native environment for Docker, as containers share the host operating system kernel. This makes Linux installations faster, more lightweight, and highly reliable compared to running Docker on Windows or macOS.
Before installing Docker, it is important to ensure that your Linux system is up to date. Most modern distributions, such as Ubuntu, Debian, Fedora, and CentOS, support Docker, but installation steps may vary slightly between them.
Here’s a general overview of the installation process on Linux:
1. Update the System
sudo apt update
sudo apt upgrade -y
This ensures that all system packages are up to date, reducing compatibility issues during Docker installation.
2. Install Required Dependencies
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
These packages allow your system to securely download Docker and manage repositories.
3. Add Docker’s Official Repository
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
sudo add-apt-repository "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Adding the official Docker repository ensures you get the latest stable version of Docker, rather than the older version that may come with your Linux distribution.
4. Install Docker Engine
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io -y
This command installs the Docker engine, command-line interface (CLI), and container runtime. Once installed, the Docker service should start automatically.
5. Verify Docker Installation
docker --version
sudo systemctl status docker
These commands check the installed Docker version and verify that the Docker service is running correctly. You should see an active (running) status for the Docker service.
6. Run Docker Without Sudo (Optional)
sudo usermod -aG docker $USER
newgrp docker
This allows your user to run Docker commands without prepending sudo. After running these commands, you may need to log out and back in for changes to take effect.
7. Test Docker Installation
docker run hello-world
Running this command downloads a test image from Docker Hub and runs it in a container. If the installation is successful, you will see the message: “Hello from Docker! Your installation appears to be working correctly.”
Docker installation on Linux offers several advantages:
- Native Performance: Containers run directly on the Linux kernel without virtualization overhead.
- Lightweight: Linux containers use fewer system resources than virtual machines.
- Compatibility: Docker works seamlessly with Linux-based orchestration tools like Kubernetes and Docker Swarm.
- Reliability: Running Docker on Linux reduces errors caused by OS compatibility issues.
Once Docker is installed on Linux, you are ready to start building, running, and managing containers. From here, you can move on to creating Docker images, managing container lifecycles, networking, volumes, and deploying applications efficiently.
