Installing and Uninstalling Docker on CentOS 7

Installing and Uninstalling Docker on CentOS 7

System Requirements

This installation tutorial is tailored for CentOS 7, as other systems may not be applicable. To proceed, ensure that the centos-extras repository is enabled by default. If it’s not, please modify the settings accordingly.

Uninstalling the Old Version of Docker

The old version of Docker is referred to as docker or docker-engine. We recommend using the Community Edition (CE) or Enterprise Edition (EE) of Docker, with CE being the preferred choice for most users. If your system is running an older version, it’s essential to uninstall it along with its associated dependencies. To do this, execute the following command:

$ sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

If your system doesn’t have an older version of Docker installed, you’ll see a prompt indicating that no matching parameters were found.

Installing Docker

If you’re installing Docker for the first time on your host, you’ll need to set up the Docker repository. This will allow you to install and update Docker from its repository.

Setting Up the Repository

To install the required packages, including yum-utils, device-mapper-persistent-data, and lvm2, execute the following command:

$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

Next, add the Docker repository using the following command:

$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Installing Docker CE

To install the latest version of Docker CE, execute the following command:

$ sudo yum install docker-ce docker-ce-cli containerd.io

After the installation is complete, Docker will be installed but not started. To start Docker, execute the following command:

$ sudo systemctl start docker

To verify the successful installation of Docker, run the hello-world image:

$ sudo docker run hello-world

You should see the following output:

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from Docker Hub.
 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/
For more examples and ideas, visit: https://docs.docker.com/get-started/

This represents a successful installation of Docker.

Uninstalling Docker

To uninstall Docker, execute the following command:

$ sudo yum remove docker-ce

This will remove the Docker package. However, the mirror, container, and custom configuration files will not be deleted automatically. To manually delete these files, execute the following command:

$ sudo rm -rf /var/lib/docker

This concludes the Docker installation and uninstallation process.