DEV Community

Nipu Chakraborty
Nipu Chakraborty

Posted on

Automating the installation of Docker on Linux using a shell script

Create a .sh file file by opening your terminal


after that open the file

Enter fullscreen mode Exit fullscreen mode

and Write this code


echo "Updating linux...."
sudo apt-get update
echo "Installing ca-certificates curl and gnupg..."
sudo apt-get install ca-certificates curl gnupg
echo "Add Docker's official GPG key:"
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add Docker repository
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

echo "Update package index again to include Docker repository"
apt update

echo "Installing Docker Engine..."
sudo apt-get install docker-ce docker-ce-cli docker-buildx-plugin docker-compose-plugin

echo "Starting and enabling Docker service"
systemctl start docker
systemctl enable docker

echo "Docker installed and started successfully."
Enter fullscreen mode Exit fullscreen mode

After complete save this file by ctrl+s
and for exit press ctrl + x

Make the script executable: chmod +x
Run the script with root privileges: sudo ./


Top comments (0)