You are currently viewing How to install Docker on a Linux machine

How to install Docker on a Linux machine

Docker is an open-source platform that leverages containerization to enable automated deployment, scalability, and management of applications. It provides an easy way to package an application with all its dependencies into a container (a standardized entity). This article highlights how to install docker on a Linux machine.

Note that there is already a package named “docker” on Kali before you attempt to install Docker; as a result, Docker must be installed under a different name. You won’t get the container version if you install Docker. Docker.io is the name of the version we will be installing. Running docker on the command line will be the proper command because all commands are identical.

how to install docker
Launch your terminal and type in the following commands to set up the Docker apt repository!
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] 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

Install the Docker packages.

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

At this stage, you can now interact with docker as a sudo user. To use docker without sudo, you will need to add your_username to the docker group using the command below.

sudo usermod -aG docker $USER  #this adds the current to the docker group.
newgrp docker #activate the changes to groups

To login in from the command line, you will need to create an account from the docker website. Navigate to https://hub.docker.com/signup to create an account or https://hub.docker.com/login to log in if you already have an account.

Configure Docker to start on boot with systemd

sudo systemctl enable docker.service
sudo systemctl enable containerd.service

Run the following command from the terminal to login to your docker hub account.

docker login

You will be prompted to key in your username and password.

A common error when trying to login: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post “http://%2Fvar%2Frun%2Fdocker.sock/v1.24/auth”: dial unix /var/run/docker.sock: connect: permission denied

Solution: Ensure to log in as the sudo us as below or ensure to add your username in the docker group.

sudo docker login

Common Docker commands that you can use

docker run image >> downloads the image from online if not present on the local repository
docker ps >> lists all running containers
docker ps -a >> lists all containers ; may be running or stopped
docker stop container-name >> stop running container
docker rm container-name >> remove container permanently
docker images >> lists all images
docker rmi image-name >> removes image ; first stop image to remove it
docker pull image-name >> pulls the image to local repository, but doesnt automatically run it.
docker inspect container-name >> gives more infor:: among them env definitions

For more information on setting up docker on other distributions, refer to the official documentation: https://docs.docker.com/get-docker/

Should you face any challenges, reach out to us, by posting a comment, or contacting us for assistance.


Make a donation to support us



Web Hosting and email hosting Packages


For web development services, SEO services, Digital marketing strategies, website set up services, web hosting and domain registration; contact Dynamic Technologies.


Related content