The Ops Community ⚙️

Cover image for Running Docker Without Sudo - EC2 server
Moses Itoya
Moses Itoya

Posted on

Running Docker Without Sudo - EC2 server

I was quite comfortable running my docker using sudo, not that I preferred it but I really had no option until I had to run a CI/CD pipeline which throws error as a result of running the commands with sudo. By default, the docker command can only be run by the root user or by a user in the docker group, which is automatically created during Docker’s installation process. If you attempt to run the docker command without prefixing it with sudo or without being in the docker group, you’ll get an output like this:

Output
docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.
See 'docker run --help'.
Enter fullscreen mode Exit fullscreen mode

This made me further troubleshoot to get a solution, this article is about my little experience resolving the issue, most especially if you experience this issue running docker on a server.

I ran my docker on an EC2 instance, even after following the commands necessary for me to run docker without using sudo. It turns out I had to reboot my server, and not just exit the terminal and ssh back in to the terminal as a lot of articles I came across advised. Well, that may have worked for others, but it did not for me. If it's on a local terminal, after following the process, you can close your terminal and come back in. The changes would be effected, but it's not so for servers, you have to reboot the server.

Also, I'd like to add that it is important you run docker without sudo especially in a Jenkins Job as it would throw errors as seen below.
docker-jenkins-1

If you want to avoid typing sudo whenever you run the docker command, add your username to the docker group. That being said, the following are steps to run Docker without sudo(I'd still like to emphasize, for EC2 servers or any other cloud provider servers,):

  1. Add your username to the docker group:

    sudo usermod -aG docker ${USER}
    
  2. Apply the new group membership. In my own case, I had to reboot my ec2 server for it to take effect, my server user had no password. If your user has a password, then run su - ${USER}. You'd be prompted to enter your password, do that and the changes would take effect.

  3. Confirm that your user is now added to the docker group by running the command groups. You should now see your user amongts the group.

That's all, you can now go ahead and run docker without sudo. This worked for me and my Jenkins job which failed worked right after the above steps
docker-jenkins

Top comments (44)

Collapse
 
brabas76 profile image
berbas

Running Docker without sudo on an EC2 server is all about improving efficiency, security, and control over system operations. In a similar way, a Boolean algebra calculator helps streamline logical problem-solving by removing unnecessary manual steps and reducing errors. Both truthcalulator.com focus on simplifying complex processes one at the infrastructure level and the other at the logic level so users can work faster, more accurately, and with greater confidence.

Collapse
 
susanamaltby profile image
SusanaMaltby

Running Docker without sudo on an EC2 server is a smart move for convenience and security. By adding your user to the docker group, you can execute Docker commands without prefixing them with sudo every time, which streamlines your workflow. Just remember to log out and back in after making the change to apply group permissions. It’s similar to setting up Pirlo TV to run smoothly—once configured right, everything just flows effortlessly. Have you noticed any other tips that make managing Docker on cloud servers easier?

Collapse
 
thomasjoe6188 profile image
thomas joe

If you’re setting up Docker on an EC2 instance, configuring it to run without sudo improves efficiency for repetitive tasks and testing workflows. While managing servers and deployments, it’s also useful to plan and track tasks or downtime accurately. You can use tools like visit time calculators to quickly compute durations, schedules, or time differences when coordinating server maintenance or container updates. This kind of calculator is especially handy when you’re planning automated builds or deployments across different time zones.

Collapse
 
dua_chaudhry_d6b278719308 profile image
Dua Chaudhry

Really helpful breakdown—especially the part about managing user permissions on an EC2 setup. I ran into similar issues when configuring dev environments, so this clarified a lot. While exploring lightweight setups, I also came across the 3patti-blue.pk/
workflow on my own project, and the permission handling concepts surprisingly overlapped. Thanks for the clear explanation!

Collapse
 
andrew_93 profile image
Andrew Wait

Running Docker without sudo on an EC2 server is definitely a useful tip for smoother workflows and better security management. If you’re also interested in exploring handy tools and apps, getmods is worth checking out for some great resources.

Collapse
 
brabas76 profile image
berbas

Running Docker without sudo on an EC2 server makes management faster and more convenient, but it’s important to configure permissions carefully to keep your environment UDISE+ portal secure. Proper group setup ensures smooth access while maintaining system safety.

Collapse
 
brabas76 profile image
berbas

Executing Docker commands without sudo on an EC2 server makes management easier. Ensure your user has xuper tv for mobile the correct group access to prevent errors or security risks.

Collapse
 
brabas76 profile image
berbas

Running Docker without sudo on an EC2 server improves efficiency, control, and overall workflow for developers. In a similar way, an NBA game benefits from optimized systems that allow smooth gameplay, faster response times, and fewer interruptions. When the underlying nba2k20apkk.com setup is streamlined, whether in cloud infrastructure or gaming mechanics, users enjoy a more responsive and enjoyable experience.

Collapse
 
brabas76 profile image
berbas

Running Docker without sudo on an EC2 server shows how smooth, secure, and efficient workflows can become with the right configuration. Klobbi’s virtual technology follows the same philosophy removing unnecessary friction so teams can focus on what matters. As a leading events registration company Singapore trusts, Klobbi delivers seamless digital tools, stress-free management, and reliable performance that feels just as streamlined as a well-optimized cloud setup.

Collapse
 
brabas76 profile image
berbas

Running Docker without sudo on an EC2 server makes deployments smoother and more secure because you avoid giving unnecessary root access. This kind of optimization is especially useful for platforms like apkloot, where managing services efficiently ensures faster delivery and better performance for users. Keeping the setup lightweight and secure helps maintain reliability as the platform scales.