Docker - Installing Docker on Linux
Installing Docker Engine on Linux
Section titled “Installing Docker Engine on Linux”This section provides detailed steps for installing Docker Engine on a Linux system, focusing on the recommended method using Docker’s official repositories. This ensures you get the latest stable version and updates.
We’ll use Ubuntu as the primary example, but the general process is similar for other supported distributions (Debian, Fedora, CentOS) – consult the official Docker documentation for distribution-specific commands.
Prerequisites
Section titled “Prerequisites”- A supported version of a Linux distribution (e.g., Ubuntu 22.04, 20.04).
- 64-bit architecture.
- Sudo privileges for your user account.
- Internet access to download packages.
Checking Kernel Version (Optional)
Section titled “Checking Kernel Version (Optional)”Docker requires a Linux kernel version 3.10 or higher. Most modern distributions meet this requirement. You can check your version using:
uname -rOutput will show the kernel release, e.g., 5.15.0-87-generic.
Installation Steps (Ubuntu Example)
Section titled “Installation Steps (Ubuntu Example)”Step 1: Uninstall Old Versions (If applicable)
If you have older versions of Docker installed (e.g., docker, docker-engine, docker.io), uninstall them first:
sudo apt-get remove docker docker-engine docker.io containerd runcIt’s okay if apt-get reports that none of these packages are installed.
Step 2: Set up the Repository
a. Update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt-get updatesudo apt-get install \ ca-certificates \ curl \ gnupg \ lsb-releaseb. Add Docker’s official GPG key:
sudo mkdir -p /etc/apt/keyringscurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpgc. Use the following command to set up the stable repository:
echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullStep 3: Install Docker Engine
a. Update the apt package index again:
sudo apt-get updateb. Install Docker Engine, CLI, containerd, and Docker Compose plugin (latest versions):
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y(docker-ce is the engine, docker-ce-cli is the command line client, containerd.io is the container runtime, docker-compose-plugin provides docker compose command).
Step 4: Verify Installation
Verify that the Docker Engine installation is successful by running the hello-world image:
sudo docker run hello-worldThis command downloads a test image and runs it in a container. A successful run will print a confirmation message.
Post-installation Steps (Manage Docker as a non-root user)
Section titled “Post-installation Steps (Manage Docker as a non-root user)”By default, the Docker daemon binds to a Unix socket owned by the root user. To run Docker commands without prefixing them with sudo, you need to add your user to the docker group (which is created during installation).
Step 5: Add your user to the docker group:
sudo usermod -aG docker $USERStep 6: Apply the group changes.
You need to log out and log back in for your new group membership to be activated. Alternatively, you can activate the changes for your current session using:
newgrp dockerAfter this, you should be able to run Docker commands without sudo.
docker run hello-worldCheck Docker Version and Info
Section titled “Check Docker Version and Info”To see detailed version information:
docker versionTo see system-wide information, including the number of containers/images, storage driver, logging driver, etc.:
docker info