sudo apt-get remove docker docker-engine docker.io containerd runc
-
Update apt and install some packages
sudo apt-get updatesudo apt-get install \ ca-certificates \ curl \ gnupg \ lsb-release -
Add GPG key
sudo mkdir -p /etc/apt/keyringscurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg -
Set up 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/null
-
Update the
aptpackage index againsudo apt-get updatesudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin -
Verify installation
sudo service docker startsudo docker run hello-world
-
Create
dockergroupsudo groupadd docker -
Add current user to the
dockergroupsudo usermod -aG docker $USER -
Activate changes to the groups
newgrp docker -
Verify changes -> able to run
hello-worldexample withoutsudodocker run hello-world
If you encounter issues like
docker: Cannot connect to the Docker daemon at unix:///home/<user>/.docker/desktop/docker.sock. Is the docker daemon running?.
it is probably because the right docker context is not selected. Execute
export DOCKER_HOST=
and try again. If it works, include the line above in your .bashrc file. See How to Troubleshoot "Cannot Connect to the Docker Daemon" Error
To enable Docker to start on boot use the systemctl enable command:
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
To disable docker starting at boot, use disable instead
sudo systemctl disable docker.service
sudo systemctl disable containerd.service