Install Docker on Ubuntu and CentOS

Install Docker on Ubuntu and CentOS

Install Docker

  1. Remove older version of docker if any:

    1. Ubuntu:

      1.    sudo apt-get remove docker docker-engine docker.io containerd runc
        
    2. CentOS:

      1.    sudo yum remove docker \
                             docker-client \
                             docker-client-latest \
                             docker-common \
                             docker-latest \
                             docker-latest-logrotate \
                             docker-logrotate \
                             docker-engine
        
  2. Update Packages:

    1. Ubuntu:

      1.    sudo apt-get update
        
    2. CentOS:

      1.    sudo yum install -y yum-utils
        
  3. Install Docker:

    1. Ubuntu:

      1.    sudo apt-get install docker.io
        
    2. CentOS:

      1.    sudo yum install docker.io
        

Done. You have successfully installed Docker in your system!

Install Docker Compose

  1. Ubuntu

    1.  sudo apt install docker-compose
      
  2. CentOs:

    1.  sudo yum install docker-compose
      

Check versions

  1. Docker

    1.  docker --version
      
  2. docker-compose

    1.  docker-compose --version
      

Check the Status of the Docker

  1. To check the status of the docker run systemctl or with service :

    1.    systemctl status docker
      
    2.    service docker stauts
      

      Active with green color shows that Docker is running.

Run Docker

Let's test Docker whether it runs or not.

  1. First, start the docker with systemctl (may need for CentOS users):

    1.    sudo systemctl start docker
      
  2. Run to test hello-world image:

    1.    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.

Uninstall Docker

  1. Stop Docker: sudo systemctl stop docker

  2. Delete the Docker packages:

    1. Ubuntu:

      1. sudo apt-get purge -y docker-engine docker docker.io docker-ce docker-ce-cli docker-compose-plugin

      2. sudo apt-get autoremove -y --purge docker-engine docker docker.io docker-ce docker-compose-plugin

    2. CentOS:

      1. sudo yum remove docker-ce docker-ce-cli containerd.io docker-compose-plugin

      2. sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine \

  3. Remove some of the docker files:

    1. Ubuntu:

      1. sudo rm -rf /var/lib/docker /etc/docker

      2. sudo rm /etc/apparmor.d/docker

      3. sudo groupdel docker

      4. sudo rm -rf /var/run/docker.sock

    2. CentOS:

      1. sudo rm -rf /var/lib/docker

      2. sudo rm -rf /var/lib/containerd

      3. sudo rm -rf /etc/docker

  4. Reboot the system: sudo reboot now

Done. You have completely removed the Docker from your system.

If you have further queries just comment on this post ๐Ÿ˜Š

ย