Why Docker?
Docker is a software platform that enables you to create, deploy, and manage applications in containers. Containers are lightweight, portable, and self-contained environments that package applications with their dependencies, making them easier to move between different environments and ensuring consistency across different platforms.
Using Docker, you can package your application code, runtime, system tools, libraries, and settings into a single container image. This allows you to run your application on any Docker-enabled infrastructure, including your laptop, a local server, or a cloud platform like AWS, Azure, or Google Cloud.
Docker simplifies the process of building, shipping, and running applications, making it easier to develop, test, and deploy software in a fast and efficient way. It enables you to break down complex applications into smaller, reusable components, which can be developed and tested independently and then integrated into the larger application.
Docker offers several benefits, such as improved efficiency, scalability, and portability of applications. It also provides a consistent environment for running applications, which reduces the risk of compatibility issues and makes it easier to troubleshoot problems.
Docker is widely used by developers, IT professionals, and organizations of all sizes to improve the speed and efficiency of their application development and deployment processes. Whether you are developing a new application or migrating an existing one, Docker can help you streamline your workflow and simplify your infrastructure.
Update Your System
Before installing any new software, it is always recommended to update your system. so…
sudo apt-get update && sudo apt-get upgradeThis will update your system’s package list and help you install any available updates.
Remove old distro docker
We don’t want any old versions of docker from the distro since they can be behind the latest version and we want nothing but the coolest newest binaries!
sudo apt-get remove docker docker-engine docker.io containerd runcIts most likely you don’t have any of these installed.
Install Docker Dependencies
Docker has some dependencies that need to be installed first. Run the following command to install the dependencies:
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-releaseAdd Docker’s GPG Key
Docker packages are signed with a GPG key to ensure their authenticity. Run the following command to add Docker’s GPG key to your system
Ubuntu:
Debian [ Debian ](#debian)-
**Ubuntu** [ Ubuntu ](#ubuntu)-
Old method [ Old method ](#old_method)sudo mkdir -m 0755 -p /etc/apt/keyringscurl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpgsudo chmod a+r /etc/apt/keyrings/docker.gpgsudo mkdir -m 0755 -p /etc/apt/keyringscurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpgsudo chmod a+r /etc/apt/keyrings/docker.gpgthe old method of adding keys is listed below but you should use the above command.
# for ubuntucurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -# or for debiancurl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -Add Docker’s Repository
Next, you need to add Docker’s repository to your system’s package sources. Run the following command to add the repository.
Debian [ Debian ](#debian)-
Ubuntu [ Ubuntu ](#ubuntu)echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullecho \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullInstall Docker
Finally, you can install Docker.
sudo apt-get updatesudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginVerify the Install
To verify that Docker is installed and working correctly, run a test container. this command will run a sample docker container called hello-world and will remove it on exit. exit it via ctrl + c
docker run --rm hello-worldIf everything is working correctly, you should see the message “Hello from Docker!” in your terminal.
yay!
Run Docker Without Sudo (You’ll Thank Yourself Later)
Fresh Docker install, everything’s working — then you open a new terminal and type docker ps and get hit with:
permission denied while trying to connect to the Docker daemon socketRight. Docker’s daemon socket is owned by root, and by default only root (and the docker group) can talk to it. Every command needs sudo unless you fix this.
The fix is one command: add your user to the docker group.
sudo usermod -aG docker $USERThen log out and back in — this is not optional. The group membership change only takes effect on a new login session. If you just run newgrp docker instead, it works for the current shell only and will confuse you tomorrow.
Verify it stuck:
groups# should include: dockerdocker ps# should NOT require sudo nowOne heads-up: being in the docker group is effectively root-equivalent. Anyone who can run docker run can trivially escape to root on the host (mount /, run privileged containers, etc.). On a personal machine or homelab box — totally fine. On a shared server, think twice and look into rootless Docker instead.
Also worth enabling Docker to start on boot while you’re in setup mode:
sudo systemctl enable dockersudo systemctl enable containerdThese are enabled by default on most installs, but it takes two seconds to confirm and saves you the “why isn’t Docker running after reboot” puzzle at 11 PM.