first uninstall old versions
sudo apt-get remove docker docker-engine docker.io containerd runc
update package index
install packages
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
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
run the following command to add the stable repository
echo \
"deb [arch=amd64 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
finally , Install Docker engine
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Verify
sudo docker run hello-world
Optional : if you want to run docker without sudo
sudo usermod -aG docker $USER
sudo chmod 666 /var/run/docker.sock
For official Docker installation guide, Click here