Setting up Rancher on Synology

Where I work, we use Docker in just about every project. We have been using Docker Cloud since it was in beta (and called Tutum) and feeling that we are starting to out-grow it. One viable alternative to Docker Cloud is Rancher, or rather, it is part of a viable alternative as it needs to be extended with build server and service discovery. But that is a whole other story.

I mainly use Linux on my desktop and laptop computer and I like setting up my own servers whenever we deploy new projects/customers. Despite this I am really fond of Synology, especially their high-end models that are capable of running Docker.

Since Synology’s Docker UI is somewhat limited, I have gone through some lengths to get it going on one of my Synology servers.

Preparing the Synology

You will need to install the Docker package (https://www.synology.com/en-us/dsm/app_packages/Docker) 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. If it is not available, you might need new hardware.

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. So, enable SSH.

Proxy settings

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 (Make sure you replace “rancher.ilix.se” with your desired hostname.)

# 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;
}
}

After saving the file, 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 on Synology and the rancher service will fail if it does not exist.

mkdir /var/log/rancher

Go to the subdomain you configured in the nginx/apache proxy in your browser, then 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.