Photo by Rubaitul Azad on Unsplash
"Unlock the Full Potential of Docker: Run Docker-Compose without Sudo"
"A step-by-step guide to configure Docker and Docker-Compose to run without sudo on Ubuntu"
Table of contents
No headings in the article.
- Create a
docker
group if it doesn't already exist:
sudo groupadd docker
- Add your user to the
docker
group:
sudo usermod -aG docker $USER
Log out and log back in to refresh your group membership.
Test that you can run Docker commands without using
sudo
:
docker run hello-world
If you see output similar to the following, Docker is working correctly:
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
- Change the ownership of the
docker-compose
binary and make it executable:
sudo chown root:docker /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
- Test that you can run
docker-compose
without usingsudo
:
docker-compose --version
If you see output similar to the following, docker-compose
is working correctly:
docker-compose version 1.29.2, build 5becea4c
That's it! You can now use docker-compose
without using sudo
. Note that you may need to log out and log back in for the group membership changes to take effect.