Docker is an open-source containerization platform that allows you to quickly build, test, and deploy applications as portable containers that can run anywhere
This tutorial covers how to install the latest version of Docker on an CentOS 8 machine from the official Docker’s repositories.
1./ Install Docker on CentOS 8
01- First, update your CentOS 8 system as below:
$ dnf update -y
02- Once you done, add the Docker repository to your system:
$ sudo curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
03- We can verify that the repository has been enabled, by looking at the output of the following command:
$ sudo dnf repolist
repo id repo name status
AppStream CentOS-8 - AppStream 5,283
BaseOS CentOS-8 - Base 1,661
docker-ce-stable Docker CE Stable - x86_64 65
epel Extra Packages for Enterprise Linux 8 - x86_64 5,635
epel-modular Extra Packages for Enterprise Linux Modular 8 - x86_64 0
extras CentOS-8 - Extras 16
04- Now that the Docker repository is enabled, run the below commands to install the latest version of Docker, .
$ sudo dnf install docker-ce --nobest
dnf list docker-ce --showduplicates | sort -r
, and next add =<VERSION>
after the package name like below:sudo dnf -y install docker-ce=<VERSION> docker-ce-cli=<VERSION> containerd.io
05- Once the installation is completed, use the below command to enable the Docker service to start at system boot:
$ sudo systemctl enable --now docker
06- When a new version of Docker is released, you can update the packages using the command sudo dnf update
. But, If you want to prevent the Docker package from being updated, use the below command to disable the Docker repository:
$ sudo dnf config-manager --set-disabled docker-ce-stable
2./ Verifying the Installation and Using Docker
By default, only root
and user with sudo
privileges can execute Docker commands. However, to execute Docker commands as non-root user you’ll need to add your user to the docker group. So, to do that, type in:
$ sudo usermod -aG docker $USER
02- Finally, to verify that Docker has been successfully installed and that you can execute the docker commands. we’ll run a test container that will print a Hello from Docker message, and exit:
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:6a65f928fb91fcfbc963f7aa6d57c8eeb426ad9a20c7ee045538ef34847f44f1
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
3./ Uninstalling Docker on CentOS 8
01- Before uninstalling Docker, run the following commands to stop all running containers and remove all docker objects:
$ docker container stop $(docker container ls -aq) $ docker system prune -a --volumes
02- You can now uninstall the Docker Engine, Docker CLI, and Containerd packages as below:
$ sudo dnf remove docker-ce docker-ce-cli containerd.io
03- Finally, delete the Docker directories by running the following commands:
$ sudo rm -rf /var/lib/docker $ sudo rm -rf /etc/docker
Conclusion
You have successfully installed Docker CE on your CentOS 8 server. To learn more about Docker, check out the official Docker documentation.
What’s Next? You might want to check the following guides: