Docker Installation

Docker is available in two editions:

  1. Community Edition (CE)
  2. Enterprise Edition (EE)

Docker Community Edition (CE) is ideal for individual developers and small teams looking to get started with Docker and experimenting with container-based apps.

Docker Enterprise Edition (EE) is designed for enterprise development and IT teams who build, ship, and run business critical applications in production at scale.

Let’s see how to install Docker CE on Linux.

Step 1 : Uninstall old versions

Older versions of Docker were called docker or docker-engine. If these are installed, uninstall them, along with associated dependencies.

CentOS :

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

Ubuntu :

$ sudo apt-get remove docker docker-engine docker.io

Step 2 : Set up the Repository.

CentOS :

  1. Install required packages. yum-utils provides the yum-config-manager utility, and device-mapper-persistent-data and lvm2 are required by the devicemapper storage driver.
    $ sudo yum install -y yum-utils \
      device-mapper-persistent-data \
      lvm2
    
  2. Use the following command to set up the stable repository. You always need the stable repository.
    $ sudo yum-config-manager \
        --add-repo \
        https://download.docker.com/linux/centos/docker-ce.repo

Ubuntu :

  1. Update the apt package index:
    $ sudo apt-get update
    
  2. Install packages to allow apt to use a repository over HTTPS:
    $ sudo apt-get install \
        apt-transport-https \
        ca-certificates \
        curl \
        software-properties-common
    
  3. Add Docker’s official GPG key:
    $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -Use the following command to set up the stable repository.
  4. Use the following command to set up the stable repository.
    $ sudo add-apt-repository \
       "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
       $(lsb_release -cs) \
       stable"

Step 3 : Install Docker CE

CentOS :

$ sudo yum install docker-ce

Ubuntu :

  1. Update the apt package index.
    $ sudo apt-get update
    
  2. Install the latest version of Docker CE.
    $ sudo apt-get install docker-ce

Step 4 : Start Docker

$ sudo systemctl start docker
$ sudo systemctl enable docker

Step 5 : Verify Docker

  1. Verify that Docker CE is installed correctly by running the hello-world image.
$ sudo docker run hello-world

Uninstalling Docker CE

Ubuntu :

  1. Uninstall the Docker CE package:
    $ sudo apt-get purge docker-ce
    
  2. Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:
    $ sudo rm -rf /var/lib/docker

CentOS:

  1. Uninstall the Docker EE package:
    $ sudo yum -y remove docker-ce
    
  2. Delete all images, containers, and volumes (because these are not automatically removed from your host):
    $ sudo rm -rf /var/lib/docker
    
  3. If desired, remove the devicemapper thin pool and reformat the block devices that were part of it.

Installation Script

The easiest way to install docker with installation script. Below is the script url. Make sure the user should have sudo privileges.

https://get.docker.com/

Execute the below two commands to install docker.

$ curl -fsSL get.docker.com -o get-docker.sh
$ sh get-docker.sh

$ curl -fsSL get.docker.com -o get-docker.sh
$ sh get-docker.sh
# Executing docker install script, commit: fc04d2c
+ sudo -E sh -c 'yum install -y -q yum-utils'
Package yum-utils-1.1.31-42.el7.noarch already installed and latest version
+ sudo -E sh -c 'yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo'
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
+ '[' edge '!=' stable ']'
+ sudo -E sh -c 'yum-config-manager --enable docker-ce-edge'
Loaded plugins: fastestmirror
............................................
...............................................
...................................................

Start docker 

$ sudo systemctl start docker

Check version of Docker

$ docker --version 
Docker version 18.02.0-ce, build fc4de44

After installation completed, execute below command to run docker commands as non root.

$ sudo usermod -aG docker centos
Advertisements

Post your Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s