I'll quickly cover the installation of docker in Ubuntu linux (yep, even when they hardly describe themselves as GNU Linux), as this is one of the most easy-to-go today distributions.
In a nutshell, you'll install the docker engine and then add some configurations to make sure you can run it without being root / sudo, and finally a useful command to add docker to the list of services loaded on boot/startup.
Here are the steps
Go to docker webpage (https://docs.docker.com/get-docker/) to get the installer for your OS.
To avoid complications down the road, run the following to remove existent installations. If there aren't, this command will no hurt
$ sudo apt-get remove docker docker-engine docker.io containerd runc
From the 3 methods of installation: - from repository, - using package, - using convenience script, the recommended is from repository. We'll then follow below steps
$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Verify the characters of the fingerprint key (lots of numbers and letters generated as a verification code), displayed when running the below command are 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 If you check just the last 8 characters (0EBF CD88) that would be enough
$ sudo apt-key fingerprint 0EBFCD88
Setup the stable repository. Notice you can go rogue and setup the unstable/edge version
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
With the repository in place, we simply run the following Ubuntu-native installer. If you're looking for a specific version, see their installation instructions (very clear and descriptive)
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Verify the docker-engine was properly installed
$ sudo docker run hello-world
Congrats! Now docker engine is installed. A group docker has been created but so far no users are added, therefore no users can run the docker engine but sudo. To allow normal users to run docker, and avoid the perils of using sudo, we need to add out user to the docker group.
$ grep "docker" /etc/group
Add your user to the docker group by using
$ sudo usermod -aG docker $USER
If the docker group doesn't exists, you must create it with the following:
$ sudo groupadd docker
To make aware your session your user has been added to a group, you have 2 options: either restart your session or run the following
$ sudo usermod -aG docker $USER
Test it worked by running
$ docker run hello-world
Add docker to the list of services running at boot
$ sudo systemctl enable docker