Setting up Rancher on Synology

Introduction

I am guessing you came here because you are looking for information about Docker, Rancher and Synology.

In case one or more of these terms are unfamiliar, here is a quick summary. Synology is a company that builds storage servers for both home and professional use, Docker is a software containerization platform and Rancher is an open source platform for managing your Docker environment.

Setup

Preparing the Synology

You will need to install the Docker package on your Synology. If your model supports it it will be available in the Package Center out of the box, as it is an official package.

Further on, you will want ssh access to your Synology as you will need to modify your web server config to proxy web traffic to your containers.

Proxy

This assumes you are running nginx on your Synology, if you are using apache instead the configuration is slightly different. However, the same setup can be achieved.

SSH your Synology and create a file called /etc/nginx/sites-enabled/proxy.conf

# Direct traffic to rancher.ilix.se to the rancher/server container.
server {  
    listen 80;
    server_name rancher.ilix.se;
    location / {
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real_IP $remote_addr;
        proxy_pass http://127.0.0.1:8080
    }
}

# Direct traffic to certain subdomains to rancher's load balancer.
server {  
    listen          80;
    server_name     ilix.se www.ilix.se public.ilix.se minecraft.ilix.se vimla.dk www.vimla.dk;
    location / {
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://127.0.0.1:8081;
    }
}

Restart nginx

synoservicectl --restart nginx

rancher/server

docker run -d --restart=unless-stopped -p 8080:8080 rancher/server  

rancher/agent

Ensure the log directory exists, docker won't create this on its own for some reason.

mkdir /var/log/rancher  

After you head into your rancher installation, go to Hosts and Add host. Then setup rancher to use http://172.17.0.1:8080 for incoming agent connections.

Then, copy the docker run command that rancher generates for your new host. It looks something like this:

sudo docker run -d --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.0.2 http://172.17.0.1:8080/v1/scripts/8E28BAFCD33C216CC5E2:1475917200000:xmID8jrtf394Y1DTKFQFFLeNjk  

For the agent to work on Synology, you need to modify it slightly. The docker.sock volume is found in /run/docker.sock and you need to mount a share into /var/lib/docker in the container. I am using /volume1/docker/rancher in this example.

The resulting docker run command should look something like this:

docker run -d --privileged -v /run/docker.sock:/var/run/docker.sock -v /volume1/docker/rancher:/var/lib/rancher rancher/agent:v1.0.2 http://172.17.0.1:8080/v1/scripts/8E28BAFCD33C216CC5E2:1475917200000:xmID8jrtf394Y1DTKFQFFLeNjk  

After you run it, wait for a couple of minutes and watch it show up in your Rancher.

comments powered by Disqus