Install Docker Engine on Centos
Install Docker Engine on Centos
Uninstall old versions
sudo yum remove docker*
sudo rm -rf /var/lib/docker/*
Installation methods
1.Install using rpm repositroy
2.Install from a package
3.Install using the convenience script
1.Install using the rpm repository
Before you install Docker Engine,you need to set up the Docker repository.
Afterward,you can install and update Docker from the repo.
Step 1 - Set up the repository
Install the yum-utils package(which provides the yum-config-manager utility)and set up the repo.
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Step 2 - Install Docker Engine
1.Install Docker Engine, containerd, and Docker Compose:
Latest:
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Specific version:
yum list {docker-ce,docker-ce-cli,containerd.io,docker-buildx-plugin,docker-compose-plugin} --showduplicates | sort -r
sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-buildx-plugin docker-compose-plugin
Step 3 - Start Docker Engine
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker
Step 4 - Verify Docker Engine Installation
sudo docker run hello-world
If it prints a confirmation message and exits,Docker Engine is successfully installed and started.
2.Install from a package
If you can't use Docker's rpm repo to install Docker Engine,you can download .rpm file for your release and install it manually.
Step 1 - Download .rpm file
Go to https://download.docker.com/linux/centos/ and choose your version of CentOS.
Then browse x86_64/stable/Packages/ and download the .rpm file for the Docker version you want to install.
sudo yum install /path/to/package.rpm (e.g. sudo yum install /tmp/package.rpm)
Step 2 - Start Docker Engine
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker
Step 3 - Verify Docker Engine Installation
sudo docker run hello-world
If it prints a confirmation message and exits,Docker Engine is successfully installed and started.
3.Install using the convenience script
Docker provides a convenience script at https://get.docker.com/
3.1.Preview script steps before running
--dry-run option to learn what steps the script will run when invoked
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh --dry-run
3.2.Install the latest stable release
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
Executing docker install script, commit: 7cae5f8b0decc17d6571f9f52eb840fbc13b2737
<...>
3.3.Install pre-releases
curl -fsSL https://test.docker.com -o test-docker.sh
sudo sh test-docker.sh
4.Upgrade Docker Engine
To upgrade Docker Engine, download the newer package files and repeat the installation procedure, using yum -y upgrade instead of yum -y install, and point to the new files.
5.Uninstall Docker Engine
Uninstall the Docker Engine, CLI, containerd, and Docker Compose packages:
sudo yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
Images, containers, volumes, or custom configuration files on your host aren't automatically removed. To delete all images, containers, and volumes
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
6.Install brainless
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker
sudo docker run hello-world
docker version