Installing Docker on Ubuntu and CentOS
June 24, 2023 Leave a comment
In this post I will follow the latest official docker steps to install docker engine from docker apt repository on Ubuntu and CentOS.
Installing docker engine on Ubuntu
I have spawned an Ubuntu server on cloud hosting and will connect with SSH to the machine. It is a fresh server of Ubuntu.
Uninstall old versions
As per the instructions we have to ensure that any conflicting packages are uninstalled.
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
Set up the repository
- Update the apt package index and install packages to allow apt to use a repository over HTTPS
sudo apt-get updatesudo apt-get install ca-certificates curl gnupg
- Add Docker’s official GPG key:
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
- Use the following command to set up the repository:
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
Install Docker Engine
- Update the apt package index:
sudo apt-get update
2. Install Docker Engine, containerd, and Docker Compose latest version.
To install the latest version, run:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- Verify that the Docker Engine installation is successful by running the hello-world image.
sudo docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.
You have now successfully installed and started Docker Engine.
Installing docker on CentOS
I am using CentOS 8.3 to install Docker version 4.11. The CentOS VM is provisioned on Azure cloud. I will follow the recommended installation method to install from docker repository from official docker installation guide.
Prerequisites
Checking the pre-requisites required for docker to be installed on any environment.
yum-utils, device-mapper-persistent-data and lvm2
Setting up the Docker repo
Install the yum-utils package (which provides the yum-config-manager utility) and set up the repository.
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Install docker latest version
1- To install Docker Engine, containerd, and Docker Compose latest version run the below.
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
2- Start and enable docker service
sudo systemctl start docker
3- Run a hello-world image container to test the installation
sudo docker run hello-world