How To Install And Run Docker In Kubuntu Or Ubuntu Without Sudo Permission

Let us see how to install docker in Kubuntu or any Ubuntu variant and run it without sudo permission as a non-root user. To start with, remove any old installation of docker or its dependencies and then install docker and configure it to access without root permission.

Install Docker

To install Docker, execute the below commands in the terminal.

# Remove previous instance /installation
$ sudo apt-get remove docker docker-engine docker.io containerd runc

# Update repo
$ sudo apt-get update

# Install Pre-requisites
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release

# Add GPG Key, so that official docker repo can be referenced
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# Add docker repo
$ 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

# Install Docker after refreshing the repo
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io

Docker Without Sudo

To run docker as a non-root user, follow the below steps. At the time of the installation of docker, a group named docker would have been created. If the group is not available, execute the command “sudo groupadd docker” to create a group named docker. Execute the below commands to add the currently logged-in user to the docker group and access docker without elevated privilege.

# Add current user to the docker group
sudo usermod -aG docker $USER

# Re-load docker group
$ newgrp docker 

# Run the hello-world container
$ docker run hello-world

Uninstall Docker

To Uninstall docker, execute the below command in terminal

# Remove Docker Packages
$ sudo apt-get purge docker-ce docker-ce-cli containerd.io

# To remove volumes, images, containers
$ sudo rm -rf /var/lib/docker
$ sudo rm -rf /var/lib/containerd

Leave a comment