peter (admin) -

Installing and Configuring Docker for Kubernetes
In this section, we will prepare our Linux system to run containers by installing and configuring Docker.
Docker provides the tools required to download container images, create containers, run them, and manage their lifecycle.
Once Docker is installed, we will configure the service, allow our normal Linux user to run Docker commands, and finally test the installation using the Docker Hello World container.
Connect to the Linux Server
First, open PuTTY and connect to the Linux machine.
After logging in with your normal user account, you should see the Linux command prompt.
Before installing Docker, it is useful to confirm which Linux distribution you are using:
cat /etc/os-release
The following installation example assumes a Debian-compatible distribution, such as Debian or Ubintu but I have included as far as I can, instuctions for RHEL-compatible distributions.
Add the Official Docker Repository
The first step is to add Docker's official software repository.
The repository contains Docker CE, which stands for:
Docker Community Edition
Using Docker's official repository allows us to install the Docker packages maintained and distributed by Docker rather than relying on potentially older packages provided by the Linux distribution.
Debian based systems
This automation script handles the complete configuration sequence: cleans old packages, configures official GPG key rings/repositories, fetches the core Docker + Compose engines, sets up user execution permissions, and enables system boot persistence.
#!/usr/bin/env bash
# Exit immediately if a command exits with a non-zero status
set -e
echo "================================================="
echo " Starting Docker Installation on Ubuntu Server "
echo "================================================="
# 1. Uninstall old versions
echo "-> Cleaning up older Docker installations..."
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do
sudo apt-get remove -y $pkg || true
done
# 2. Set up the repository
echo "-> Updating apt package index and installing prerequisites..."
sudo apt-get update
sudo apt-get install -y ca-certificates curl
echo "-> Adding Docker's official GPG key..."
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo "-> Setting up the stable repository..."
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# 3. Install Docker Engine
echo "-> Updating apt index with new repository..."
sudo apt-get update
echo "-> Installing Docker Engine, CLI, Containerd, and Compose..."
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# 4. Post-installation configurations
echo "-> Configuring non-root user access (adding $USER to docker group)..."
sudo usermod -aG docker $USER
echo "-> Enabling Docker services to start on boot..."
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
echo "================================================="
echo " Setup complete! "
echo "================================================="
echo "IMPORTANT: Please log out and log back in (or restart"
echo "your SSH session) for the non-root group changes to apply."
echo ""
echo "To test your installation after logging back in, run:"
echo "docker run hello-world"
echo "================================================="
How to use this script on your Ubuntu server
- Paste the content into a new file called install-docker.sh
- Make the file executable:
bash
chmod +x ./install-docker.sh - Execute the script:
bash
./install-docker.sh
RedHat Based Systems
First install the DNF plugins if required:
sudo dnf install -y dnf-plugins-core
Then add the official Docker repository:
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
You can confirm that the repository is available with:
dnf repolist
Install Docker
We can now install the main Docker components:
sudo dnf install -y docker-ce docker-ce-cli containerd.io
These packages provide several important components.
Docker CE
docker-ce provides the Docker Engine.
The Docker Engine is responsible for creating and managing Docker containers.
Docker CE CLI
docker-ce-cli provides the Docker command-line interface.
This gives us the familiar:
docker
command.
For example:
docker ps
can be used to display running containers.
containerd
containerd.io provides containerd, the container runtime used underneath Docker Engine.
The basic relationship can be represented as:
User
|
v
Docker CLI
|
v
Docker Engine
|
v
containerd
|
v
Containers
After installation has completed, Docker is installed but we should also make sure the Docker service is running.
Start and Enable Docker
We want Docker to start immediately and also start automatically whenever Linux boots.
Both operations can be performed with:
sudo systemctl enable --now docker
The --now option starts the service immediately, while enable configures it to start automatically during boot.
Check the Docker Service
We can verify that Docker is running with:
sudo systemctl status docker --no-pager
The --no-pager option displays the information directly in the terminal rather than opening it in an interactive pager.
You should see something similar to:
Loaded: loaded
Active: active (running)
The important part is:
active (running)
This confirms that the Docker daemon is currently running.
You can also check whether Docker has been enabled at boot:
systemctl is-enabled docker
The expected result is:
enabled
At this point Docker has been:
-
Installed
-
Started
-
Enabled at boot
Running Docker as a Normal User
By default, you may need to use sudo when running Docker commands.
For example:
sudo docker ps
For a learning environment, we can add our user to the docker group so that Docker commands can be executed without repeatedly using sudo.
Run:
sudo usermod -aG docker $USER
The options mean:
-a Append the user to another group
-G Specify the supplementary group
$USER automatically refers to the currently logged-in username.
You can check your username with:
echo $USER
Apply the New Group Membership
Group membership changes normally take effect after you log out and log back in.
Alternatively, for the current terminal, you can run:
newgrp docker
You can then check your groups with:
groups
You should see docker included in the output.
You should now be able to run:
docker ps
without using sudo.
Security note: Membership of the
dockergroup effectively provides powerful root-level capabilities on the machine. Only trusted users should be added to this group.
Test Docker with Hello World
Now that Docker is installed and running, we should test it.
Docker provides a very small test image called:
hello-world
Run:
docker run --rm hello-world
The --rm option tells Docker to automatically remove the container after it finishes running.
What Happens When We Run the Command?
When we execute:
docker run --rm hello-world
Docker performs several operations.
First, it checks whether the hello-world image already exists locally.
We can represent the process as:
docker run
|
v
Check local images
|
+---- Image exists ----> Use local image
|
+---- Image missing
|
v
Docker Hub
|
v
Download image
|
v
Create container
|
v
Run container
If the image does not exist locally, Docker downloads it from a container registry.
Docker then creates a container from the image and runs it.
Hello from Docker
If everything is working correctly, the output should contain:
Hello from Docker!
This simple message confirms several important things.
Docker has successfully:
-
Connected to the Docker daemon
-
Located or downloaded a container image
-
Created a container
-
Started the container
-
Executed the application inside the container
Because we used:
--rm
Docker also removes the stopped container automatically after the test has completed.
Check Docker Images
We can see which container images are stored locally with:
docker images
You should see the hello-world image in the list.
For example:
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest xxxxxxxxxxxx ... ...
Check Running Containers
To display currently running containers:
docker ps
The Hello World container will not appear because it runs briefly and then exits.
To display running and stopped containers:
docker ps -a
Because we used --rm, the Hello World container should have been automatically removed.
Check the Docker Version
Finally, we can check which version of Docker is installed.
Run:
docker version
This displays detailed information about both the Docker client and server.
You can also use:
docker --version
for a shorter result.
For example:
Docker version 29.x.x, build xxxxxxx
The exact version will depend on the version available from the Docker repository when you install it.
Knowing the Docker version is useful when troubleshooting compatibility problems or checking documentation.
Understanding the Complete Docker Setup
Our Docker installation can now be represented as:
Linux Server
|
v
Docker CLI
|
v
Docker Engine
|
v
containerd
|
v
Container Images
|
v
Containers
The user sends commands through the Docker CLI.
The Docker Engine processes those commands and works with containerd to manage containers.
Container images provide the files and configuration required to create those containers.
Docker and Kubernetes
It is useful to understand an important distinction when learning modern Kubernetes.
Docker is an excellent tool for learning, building, testing, and running containers, and it can also be used as a driver for tools such as Minikube.
However, modern Kubernetes does not require Docker Engine on its nodes.
Kubernetes communicates with container runtimes through the Container Runtime Interface (CRI). A kubeadm-based Kubernetes cluster commonly uses containerd or CRI-O directly.
The relationship in a Kubernetes node is typically:
Kubernetes
|
v
Kubelet
|
| CRI
v
Container Runtime
|
v
Containers
So while Docker is extremely useful for learning container concepts and for certain local Kubernetes environments, it is important to distinguish Docker Engine from the container runtime used directly by Kubernetes.
Docker Installation Complete
At this point, Docker has been successfully:
-
Installed from Docker's official repository
-
Started
-
Enabled to start automatically
-
Configured for use by our normal user
-
Tested with the Hello World image
-
Verified using the Docker version information
Our Linux machine can now successfully download container images and run containers.
This gives us the container foundation we need as we continue building our Kubernetes learning environment.
Comments (0)
There are no comments yet. Be the first to comment.
Log in or register to leave a comment. all comments are subject to admin approval