Search This Blog

Saturday, February 10, 2018

Complete Docker Installation on Multiple Platforms (CentOS/Red Hat)

Before enabling any repositories, be sure that you have installed the necessary required packages to support Docker but are not automatically installed as dependencies.


[root@vodafone-openstack1 ~]# yum install -y yum-utils device-mallerpper-persistent-data lvm2

Using the appropriate yum utility, add the Docker CE repository at https://download.docker.com/linux/centos/docker-ce.repo; update the local yum cache once added.


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



[root@vodafone-openstack1 ~]# yum update
Loaded plugins: fastestmirror
docker-ce-stable                                                                                      | 2.9 kB  00:00:00
docker-ce-stable/x86_64/primary_db                                                                    |  11 kB  00:00:00
Loading mirror speeds from cached hostfile
 * base: mirror.ash.fastserv.com
 * epel: s3-mirror-us-east-1.fedoraproject.org
 * extras: mirror.net.cen.ct.gov
 * nux-dextop: mirror.li.nux.ro
 * updates: mirrors.advancedhosters.com

Execute the appropriate command to install the Docker CE application from the newly-configured repository.

[root@vodafone-openstack1 ~]# yum install docker-ce

Once installed, verify that the 'docker' group exists on your system. If not, create one. Once verified or created, add the 'user' account to that group so that sudo rights are not necessary to run Docker commands.

[user@tcox4 ~]$ cat /etc/group | grep docker
docker:x:988:


Running Command # docker images by non root user

root@vodafone-openstack1 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

[root@vodafone-openstack1 ~]# exit
logout
[user@vodafone-openstack1 ~]$ 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.35/images/json: dial unix /var/run/docker.sock: connect: permission denied

[user@vodafone-openstack1 ~]$ sudo su -
[sudo] password for user:
Last login: Sat Feb  3 11:57:17 UTC 2018 on pts/1

[root@vodafone-openstack1 ~]# cd /var/run

[root@vodafone-openstack1 run]# ls -al docker.sock
srw-rw----. 1 root docker 0 Feb  3 12:20 docker.sock

[root@vodafone-openstack1 run]# usermod -aG docker user
[root@vodafone-openstack1 run]# exit
logout
[user@vodafone-openstack1 ~]$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
[user@vodafone-openstack1 ~]$


Using the appropriate service management commands, enable the Docker CE service so that it starts automatically on boot, and then start the Docker CE service. Verify that it is running after. NOTE: You will need to log out and then back in for the new group setting above to work.


[root@vodafone-openstack1 ~]# systemctl enable docker && systemctl start docker && systemctl status docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2018-02-03 12:20:32 UTC; 64ms ago
     Docs: https://docs.docker.com
 Main PID: 18867 (dockerd)
   Memory: 24.3M
   CGroup: /system.slice/docker.service
           ─18867 /usr/bin/dockerd
           └─18870 docker-containerd --config /var/run/docker/containerd/containerd.toml

Feb 03 12:20:30 vodafone-openstack1.mylabserver.com dockerd[18867]: time="2018-02-03T12:20:30.097970477Z" level=info ms...e]"
Feb 03 12:20:30 vodafone-openstack1.mylabserver.com dockerd[18867]: time="2018-02-03T12:20:30.921110598Z" level=info ms...se"
Feb 03 12:20:31 vodafone-openstack1.mylabserver.com dockerd[18867]: time="2018-02-03T12:20:31.176534012Z" level=info ms...ds"
Feb 03 12:20:31 vodafone-openstack1.mylabserver.com dockerd[18867]: time="2018-02-03T12:20:31.177436342Z" level=info ms...t."
Feb 03 12:20:31 vodafone-openstack1.mylabserver.com dockerd[18867]: time="2018-02-03T12:20:31.922590822Z" level=info ms...ss"
Feb 03 12:20:32 vodafone-openstack1.mylabserver.com dockerd[18867]: time="2018-02-03T12:20:32.110700926Z" level=info ms...e."
Feb 03 12:20:32 vodafone-openstack1.mylabserver.com dockerd[18867]: time="2018-02-03T12:20:32.174015008Z" level=info ms...-ce
Feb 03 12:20:32 vodafone-openstack1.mylabserver.com dockerd[18867]: time="2018-02-03T12:20:32.174191177Z" level=info ms...on"
Feb 03 12:20:32 vodafone-openstack1.mylabserver.com dockerd[18867]: time="2018-02-03T12:20:32.254348813Z" level=info ms...ck"
Feb 03 12:20:32 vodafone-openstack1.mylabserver.com systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.



To test that the service is listening AND Step #4 was correctly completed, pull the default repository image called 'httpd' to your server.

[user@tcox4 ~]$ docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
aa18ad1a0d33: Pull complete
2b28e4afdec2: Pull complete
802b6cd5ed3b: Pull complete
6f2336b7c318: Pull complete
d7c441746c9e: Pull complete
a36c7f15867a: Pull complete
a0d42b9fc107: Pull complete
Digest: sha256:cf774f082e92e582d02acdb76dc84e61dcf5394a90f99119d1ae39bcecbff075
Status: Downloaded newer image for httpd:latest

Run the appropriate Docker CE command that will display a list of all images that are locally installed.


[user@tcox4 ~]$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
httpd               latest              cf6b6d2e8463        42 hours ago        182MB

1 comment: