How to install Docker

by admin May 10, 2020 at 4:52 pm

1. Run yum update to have server up to date.

[root@ansiblenode3 ~]# yum update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.twinlakes.net
 * extras: mirror.linux.duke.edu
 * updates: centos.mirror.constant.com
No packages marked for update

2. Install the utils, lvm2 & persistent-data packages

[root@ansiblenode3 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2

3. Download the docker repo

[root@ansiblenode3 ~]# 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

4. Install the docker packages

# yum install docker-ce

5. Enable and start the docker service

[root@ansiblenode3 ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

[root@ansiblenode3 ~]# systemctl start docker

[root@ansiblenode3 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2020-05-10 12:43:35 EDT; 9s ago
     Docs: https://docs.docker.com
 Main PID: 1247 (dockerd)
    Tasks: 8
   Memory: 42.3M
   CGroup: /system.slice/docker.service
           └─1247 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

May 10 12:43:34 ansiblenode3 dockerd[1247]: time="2020-05-10T12:43:34.443105398-04:00" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc
May 10 12:43:34 ansiblenode3 dockerd[1247]: time="2020-05-10T12:43:34.443124485-04:00" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock 0 ..." module=grpc
May 10 12:43:34 ansiblenode3 dockerd[1247]: time="2020-05-10T12:43:34.443139831-04:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
May 10 12:43:34 ansiblenode3 dockerd[1247]: time="2020-05-10T12:43:34.536606897-04:00" level=info msg="Loading containers: start."
May 10 12:43:34 ansiblenode3 dockerd[1247]: time="2020-05-10T12:43:34.948006545-04:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option ...d IP address"
May 10 12:43:35 ansiblenode3 dockerd[1247]: time="2020-05-10T12:43:35.208356390-04:00" level=info msg="Loading containers: done."
May 10 12:43:35 ansiblenode3 dockerd[1247]: time="2020-05-10T12:43:35.247824582-04:00" level=info msg="Docker daemon" commit=afacb8b graphdriver(s)=overlay2 version=19.03.8
May 10 12:43:35 ansiblenode3 dockerd[1247]: time="2020-05-10T12:43:35.248143229-04:00" level=info msg="Daemon has completed initialization"
May 10 12:43:35 ansiblenode3 systemd[1]: Started Docker Application Container Engine.
May 10 12:43:35 ansiblenode3 dockerd[1247]: time="2020-05-10T12:43:35.287580202-04:00" level=info msg="API listen on /var/run/docker.sock"
Hint: Some lines were ellipsized, use -l to show in full.
[root@ansiblenode3 ~]# 

6. Run docker images command to verify the docker installed properly

[root@ansiblenode3 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

7. Add the normal users to docker group to run the docker commands

[root@ansiblenode3 ~]# su - ramesh

[ramesh@ansiblenode3 ~]$ docker images
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/images/json: dial unix /var/run/docker.sock: connect: permission denied
[root@ansiblenode3 ~]# ls -al /var/run/docker.sock 
srw-rw----. 1 root docker 0 May 10 12:43 /var/run/docker.sock

[root@ansiblenode3 ~]# usermod -aG docker ramesh

[root@ansiblenode3 ~]# su - ramesh
Last login: Sun May 10 12:44:36 EDT 2020 on pts/0

[ramesh@ansiblenode3 ~]$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

Leave a Reply