Run the Docker on Ubuntu without sudo Command

Run the Docker on Ubuntu without sudo Command

Docker is the most popular tool for running container services. It's compatible with all computer operating systems. It's used for running web applications, web tools, server applications, cloud admin panels, and more. You can even run the operating system's virtual machine over the Docker container. In this article, we won't discuss Docker in more detail. Instead, we'll answer a key question: How can we run Docker on Ubuntu without the sudo command.

When we try to access Docker with a newly created user, we might encounter a "permission denied" error. This means that the particular user is not allowed to modify these settings. In this case, you can follow the given steps.

Docker on Ubuntu without sudo

There are two ways to access Docker on Ubuntu without sudo. The first is to run Docker as a root user, and the second is to add the user to the Docker group.

Run the Docker with Root

If you are an existing sudo user but are unable to run Docker with this account, one useful step is to switch to the root user by inputting the sudo su command. You can manage and access all Docker services through this step.

Add the User to Docker

For newly created users, when we try to run any Docker activity, we might encounter a "permission denied" error. If you don't plan to switch to the root user for your Docker project, you need to add this user to the Docker group.

For example, if you input the "docker images" command in the terminal and get a "permission denied" message, you can check the group of this user by inputting the "groups" command in the terminal.

docker image command to check current user permistion

If only "sudo" is available, you can add this user to Docker by inputting the given command:

$ sudo usermod -aG docker $USER
inet70@docker-ubuntu:~$ sudo usermod -aG docker inet70
[sudo] password for inet70: 
inet70@docker-ubuntu:~$ sudo reboot
Connection to 146.190.127.119 closed by remote host.
Connection to 146.190.127.119 closed.

In the "$USER" section, input the current user's username who needs to be added to Docker. Here, "-aG" is used to append the group. After completion, input "sudo reboot" to reboot the system and update the group policy for this user.

After rebooting, when you input the "groups" command in the terminal, the Docker group should be available for this user.

test docker without sudo

For testing purposes, you can check the Docker images. All the Docker images should be shown and working for this user.

Thanks for reading this content. If you liked this content and are interested in getting more content like this, subscribe to this blog for more tutorials.