Are you tired of having to run docker as root? Well look no further, the solution is here. The instructions below were tested on Ubuntu 20.04
First, if you haven't already, install and enable docker:
sudo apt update && sudo apt install docker.io --yes
sudo systemctl enable --now docker
Download latest docker compose (or replace latest
in url with desired version number):
curl -s https://api.github.com/repos/docker/compose/releases/latest \
| grep "browser_download_url.*docker-compose-$(uname -s)-$(uname -m)" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -i - -O $HOME/Downloads/docker-compose
Move docker compose to /usr/local/bin/
:
sudo mv $HOME/Downloads/docker-compose /usr/local/bin/docker-compose
To allow non-root docker execution, add the current user to docker group:
sudo groupadd docker # create group if does not exist
sudo usermod -aG docker $USER # add current user to the docker group
sudo chgrp docker /usr/local/bin/docker-compose # docker-compose now belongs to docker group
sudo chmod 750 /usr/local/bin/docker-compose # allow docker group memebers to execute docker-compose [Learn more about linux permissions](https://www.linux.com/training-tutorials/understanding-linux-file-permissions/)
newgrp docker # apply permission changes. run this OR log in/out your user OR reboot your machine
Test that docker and docker-compose now work without sudo:
cd ~
docker run hello-world
docker-compose --version
And that's it