In this post, we will discuss the steps to install docker in Ubuntu using the repository. At first, we need the update the apt package index.
sudo apt-get update
Since we will be using repository we need to allow apt to use the repository over HTTPS:
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
We will use curl command in order to add the Docker’s GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Here, we will be using stable repo. You can use the nightly or test repo as per your requirement.
echo \ “deb [arch=$(dpkg –print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
tip : nightly packages are released every night that can be used for testing the last feature added.
test repo are those repo related to test and upcoming release. Learn More Here
If you want to use nightly or test repo, you can simply add nightly or test after the word stable.
Let’s install docker now
sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli containerd.io
Once the docker is installed, we need to install docker-composer
sudo apt install docker-compose
Awesome, we are all set now. Let’s verify if our docker is working fine. Use the following command in order to see the status of our docker.
sudo systemctl status docker
You can see the status is Active (running). If the status is inactive (dead). You need to run it using the following command.
sudo systemctl enable –now docker
Restart your ubuntu os if you cannot enable the docker using previous command.
tip : press q to exit the previous command
Now, let’s verify if our docker is working well with dockerhub. using the following command.
sudo docker run hello-world
This command execute hello-world image from the dockerhub as no local image is available. If you see Hello from Docker! VOILA Everything is working fine till now.
tip : use ” sudo docker images ” to see all the images that is available locally for now you will only see hello-world