Skip to content

Instantly share code, notes, and snippets.

@emmanuelnk
Last active October 21, 2020 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emmanuelnk/245fd4f4d5f016e3ce52a978874769b7 to your computer and use it in GitHub Desktop.
Save emmanuelnk/245fd4f4d5f016e3ce52a978874769b7 to your computer and use it in GitHub Desktop.
Install and use docker and docker-compose on Linux, Ubuntu without SUDO (NON-ROOT)

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 ☺️! Enjoy executng non-root docker and docker-compose!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment