Add remote CentOS to docker-machine

This tutorial shows how to add a remote CentOS to your local docker-machine.

Conditions

Preparation

The first step is to install docker on CentOS 7.

# update packages
$ yum update

# change into repository directory
$ cd /etc /yum.repos.d/

# add the docker repo
$ tee docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

# install docker
$ yum install docker-engine

# start docker
$ service docker start

# check version
$ docker --version && docker images

Second step is to setup firewall rules on CentOS 7.

# change firewalld
$ firewall-cmd --permanent --zone=public --add-port=2376/tcp
$ firewall-cmd --reload

# check rules
$ firewall-cmd --list-all

The last step on CentOS 7 is to share ssh public key.

# create ssh key (local)
$ ssh-keygen -t rsa -b 4096

Add CentOS 7 server to docker-machine

# list docker-machines
$ docker-machine ls

# add remote to local docker-machine
$ docker-machine create -d generic --generic-ip-address <IP | Domain> --generic-ssh-key ~/.ssh/id_rsa --generic-ssh-user <user> myServer

# pointing shell
$ eval $(docker-machine env myServer)

# list docker-machines
$ docker-machine ls
...
NAME        ACTIVE   DRIVER       STATE     URL                SWARM   DOCKER    ERRORS
myServer      *      generic      Running   tcp://<ip>:2376    v1.11.1