Docker installation in Centos 7 in virtual box.
Docker installtion easy way
sudo yum update
sudo yum install docker
sudo systemctl start docker
sudo systemctl status docker
sudo systemctl enable docker
sudo docker info
sudo docker version
prerequisite:
centoes 7 operating system
64 bit
sudo user permission
second way to install docker from docker official repojetory::
sudo yum check-update
Now run this command. It will add the official Docker repository, download the latest version of Docker, and install it:
curl -fsSL https://get.docker.com/ | sh
After installation has completed, start the Docker daemon.
sudo systemctl start docker
sudo systemctl status docker
sudo systemctl enable docker
step-2: Executing docker without sudo command.If you want to avoid typing sudo
whenever you run the docker
command, add your username to the docker group:
sudo usermod -aG docker $(whoami)
sudo usermod -aG docker username
Another method:
Docker installation By a single script:ubuntu 22.04
#!/bin/bash
# Script to install Docker on Ubuntu 22.04
# Step 1: Update the apt package index
sudo apt-get update
# Step 2: Install packages to allow apt to use a repository over HTTPS
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common \
gnupg
# Step 3: 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
# Step 4: Set up the stable 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
# Step 5: Update the apt package index again
sudo apt-get update
# Step 6: Install the latest version of Docker Engine, CLI, and containerd
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
# Step 7: Add your user to the Docker group to run Docker without sudo
sudo usermod -aG docker $USER
# Step 8: Enable and start Docker service
sudo systemctl enable docker
sudo systemctl start docker
# Print Docker version to verify installation
docker --version
echo "Docker installation completed successfully. Please log out and log back in to apply the user group changes."
Save the script to a file: Save the above script to a file, for example,
install_
docker.sh
Make the script executable
chmod +x install_docker.sh ./install_docker.sh