0 - Introduction
If you ever tried to host a service like a git alternative, a website, a minecraft server, or any random service or app, you might know how tiring random missing dependencies or other problems can be when they appear. Well, docker can help you relieve some of those problems.
Starting by its ease of use, docker let’s you write a ‘docker compose’ file that tells your ‘container’ which app to run, on which port and how, then you just need to start it and let it run.
Having applications or services in this way also has the advantage of keeping them ‘containerized’, which means your host system has a little extra protection against attacks or vulnerable applications.
Now, before we tell you how to install it, let’s update your system:
sudo apt update
sudo apt upgrade
And for those who had an older version already installed, run this command to remove it:
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
1 - Install
Before being able to install docker, you must add their repository to your sources, and you can do that by copying the script below, pasting it in your terminal and pressing enter:
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
After the repository is added, you can actually install docker and its dependencies with the following command:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Now we need to add yourself to the docker group so that you have permission to run docker commands without sudo, and we can do that with:
sudo groupadd docker
sudo usermod -aG docker $USER
Attention: Restart your computer before continuing!!
After that is done, you can now run a ‘hello-world’ container to test your installation, and if everything is okay, when you run the command below, it should download and run the container giving you a success message.
docker run hello-world
And that’s it, you should now have an installation of docker ready for any container you require it to run!
Thanks for reading and stay tuned for more tech insights and tutorials. Until next time, and keep exploring the world of tech!