Local Docker with CentOS 7
playing with whales at home

We all like computers, and sometimes we have computers at home we don’t use. A good way to reuse those machines is to install Docker on them and use it to run some personal project we might have. The instructions to set it up are available on the Internet, but they are on different URLs, and it is complicated to go back and forward to get the right script to run or the correct command to execute. In this blog, I will describe how I was able to reuse one of these not-so-used machines as a Docker host. I will try to summarize here the following:

I am assuming you are using Mac on the local station and you have installed Docker locally already. It is possible to do it from a Window machine as well, but I haven’t try that yet.

Installing CentOS 7

There are multiple ways to install CentOS, but I downloaded the DVD from here. In particular, this was the image CentOS-7-x86_64-DVD-1511.iso I used. On the installation, I choose “Minimal” to save some space, and one thing to remember is to enable the Network and write down the IP of the server. During the installation write down root password too(at home, we don’t need to create another user due to the security problems we might have by using root all the time; so, we will be using root to access the server.)

After the installation is completed, you can use the IP and the root password to access the server with ssh, and the journey begins:

(the server should be accessible with ssh without any changes)

Installing Docker

Now, we start following instructions on different pages. The first one is to install Docker on CentOS https://docs.docker.com/engine/installation/linux/centos/. Here is the commands summary:

With that, we update all our packages and add the docker Yum repo to the server. Next, we install docker:

With Docker installed and Docker daemon running, we are ready to test that is working:

Great! We have Docker installed and running, but we cannot access it from our local station yet.

Configuring Docker daemon

By default, Docker daemon listen on unix:///var/run/docker.sock, we need to configure it to listen on a TCP port we can access outside the server. We need to follow the instruction on another page: https://docs.docker.com/engine/admin/#configuring-docker-1

Here is the command summary:

Add the following to that file:

Now, we need to restart the daemon:

(If there is any error, it is possible to see them in details with journalctl -u docker tail -100)

What we did here is certainly no good for any other place than our local network at home. There is no security in place. Everybody on the network will have root access to our server, but it is just to play with whales at home, right? On other environments, we need to secure this as recommended here

So far, if we try to access Docker Remote APIs, we could not do it because the local firewall is not allowing connections to the port 2376 where we configured Docker to listen. We need another page to do that: http://ask.xmodulo.com/open-port-firewall-centos-rhel.html Here is the command summary:

Accessing Docker from local station

Finally, everything is set! On our local station, we need to tell the docker client where is the host:

You should see CentOS Linux 7 operating system as part of the “docker info” output.

It was a long journey to get here, but I could convert a not-too-used machine to a docker host, and start deploying to it. I hope this will be useful to somebody in the same situation.

Enjoy!

*****
Written by Darien Martinez Torres on 17 December 2016