Loading...

Install docker on CentOS as virtual machine

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

Working with Windows sucks. Working with Docker and Windows also sucks. Working in a company with Docker and Windows sucks big time. Besides security and proxy everything is a hassle, because connectivity, filesystem or permissions might not work out of a box. Too many workarounds for docker freshmen. So I decided to run docker in a CentOS virtual machine. That is the closest thing to RHEL. This post demonstrates how to get Docker installed and properly configured, so you can work with docker with great pleasure :wink: .

Installation

docker.repo

First step is to create a custom repo for docker:

[root@localhost vinh]# sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
> [dockerrepo]
> name=Docker Repository
> baseurl=https://yum.dockerproject.org/repo/main/centos/7/
> enabled=1
> gpgcheck=1
> gpgkey=https://yum.dockerproject.org/gpg
> EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg

Download latest repo information

[root@localhost vinh]# yum update
Loaded plugins: fastestmirror
dockerrepo                                                                                             | 2.9 kB  00:00:00
dockerrepo/primary_db                                                                                  |  25 kB  00:00:00
Loading mirror speeds from cached hostfile
 * base: centos.schlundtech.de
 * extras: centos.mirror.net-d-sign.de
 * updates: centos.bio.lmu.de
No packages marked for update

Install Docker

[root@localhost vinh]# yum install docker-engine
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.schlundtech.de
 * extras: centos.mirror.net-d-sign.de
 * updates: centos.bio.lmu.de
Resolving Dependencies
..
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================================
 Package                              Arch                 Version                             Repository                Size
==============================================================================================================================
Installing:
 docker-engine                        x86_64               1.12.5-1.el7.centos                 dockerrepo                19 M
Installing for dependencies:
 audit-libs-python                    x86_64               2.6.5-3.el7                         base                      70 k
 checkpolicy                          x86_64               2.5-4.el7                           base                     290 k
 docker-engine-selinux                noarch               1.12.5-1.el7.centos                 dockerrepo                28 k
 libcgroup                            x86_64               0.41-11.el7                         base                      65 k
 libseccomp                           x86_64               2.3.1-2.el7                         base                      56 k
 libsemanage-python                   x86_64               2.5-4.el7                           base                     103 k
 libtool-ltdl                         x86_64               2.4.2-21.el7_2                      base                      49 k
 policycoreutils-python               x86_64               2.5-9.el7                           updates                  444 k
 python-IPy                           noarch               0.75-6.el7                          base                      32 k
 setools-libs                         x86_64               3.3.8-1.1.el7                       base                     612 k
Transaction Summary
==============================================================================================================================
Install  1 Package (+10 Dependent packages)
Total download size: 21 M
Installed size: 85 M
Is this ok [y/d/N]: y

Service Configuration

Enable service

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

Start docker

[root@localhost vinh]# sudo systemctl start docker

Run Hello Docker

Run hello world

[root@localhost vinh]# docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
Pulling repository docker.io/library/hello-world
docker: Error while pulling image: Get https://index.docker.io/v1/repositories/library/hello-world/images: dial tcp 52.207.178.113:443: getsockopt: connection refused.
See 'docker run --help'.

Bypass with proxy

This section assumes you are using CNTLM as single proxy solution. Otherwise you need to replace it with your real proxy data.

Create custom settings for docker

[root@localhost vinh]# mkdir /etc/systemd/system/docker.service.d

We add the proxies for http and https. Additionally if you run an internal docker registry, put it on the NO_PROXY line.

[root@localhost vinh]# vim /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://10.0.2.2:3128" "HTTPS_PROXY=https://10.0.2.2:3128" "NO_PROXY=localhost,127.0.0.1,artifactory.cinhtau.net"

Reload and check

[Service]
[root@localhost vinh]# systemctl show --property=Environment docker
Environment=HTTP_PROXY=http://10.0.2.2:3128 HTTPS_PROXY=https://10.0.2.2:3128 NO_PROXY=localhost,127.0.0.1,artifactory.six-group.net

It it mandatory to restart

[root@localhost vinh]# systemctl restart docker

Run hello world again

[root@localhost vinh]# docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c04b14da8d14: Pull complete
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Status: Downloaded newer image for hello-world:latest
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 the 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 Hub account:
 https://hub.docker.com
For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

Have fun with Docker under Linux!

Please remember the terms for blog comments.