11/14/2021»»Sunday

Synology Docker Image

Most of my hobby applications run as Docker containers on a Synology NAS and I really love this cheap and easy possibility to run applications at home.

For managing the Docker containers I used the Synology Docker management user interface until now.It is a lightweight possibility to download Docker images, and to manage the Docker containers without having to deal with the command line.

Sometimes there is a need for settings, which can’t be done with the Synology user interface.This is e.g. the case, if you want to set a specific Docker log driver to collect the logs of Docker containers in a central place - at least this was the trigger for me to check, which alternatives are available.

I already knew Portainer but never used it on a NAS which usually comes with some wrappers around well-known tools like Docker, which sometimes lead to problems.So I decided to give it a try and to document the necessary setup steps in this blog post.

Docker Hub has automated builds, which even allows to trigger a re-build when the upstream image was build - though, this only works, if the upstream image is not an official image (Imagine millions of custom images beeing re-build every time ubuntu, alpine or a debian base images are updated. This would put a lot of stress on Docker Hub). To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. The Docker daemon pulled the 'hello-world' image from the Docker Hub. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.

Portainer itself will also run as a Docker container which also simplifies the setup.

First I thought that the easiest approach would be creating the Portainer Docker container using the Synology NAS user interface.I tried it and soon I recognized, that it is not possible to mount something other than network shares as volumes.Therefore, it is not possible to mount /var/run/docker.sock as required.This means, it is unfortunately not possible to manage the Portainer Docker container using the Synology user interface.

That’s why the Portainer Docker container needs to be created using the command line.Please connect to the NAS via SSH.Then replace the placeholders in the command below and run the resulting command via SSH on the NAS.

shell scriptsudo docker run -d -p <port>:9000 --name=<name> --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v <volume>:/data portainer/portainer:<version>

The placeholders used are:

  • port: The port on which the Portainer web application will be reachable.Make sure this port is not in use yet.I used 9000 as value.
  • name: The name you want to use for the Portainer Docker container.I used portainer as value.
  • volume: The path to the directory on the NAS which is used to store persistent data belonging to Portainer.I used /volume1/docker/portainer/data.
  • version: The version of the Portainer Docker image.I recommend to always specify a specific version to have full control over the version used for the container and to make the setup reproducible.If this is not relevant for you, feel free to use latest.I used 1.24.0.

This command creates the Portainer Docker container and takes care, that it is automatically started e.g. if the NAS was rebooted.

Once the Docker container is created and running, you can access the Portainer user interface in the browser.Just replace the placeholders in <http https>://<nas-domain-or-ip>:<port> and navigate to the resulting URL.

The placeholders used are:

  • <http https>: Choose the protocol you use to access the NAS.
  • <nas-domain-or-ip>: The domain or IP you use to access the NAS.
  • <port>: The port you used as placeholder in the previous section.

The page you will see should look similar to the one below.It is used to create the first user on Portainer which will get administrator permissions automatically.Specify the desired username and a safe password and click on the button to create this user.

The next step is to further configure Portainer.You need to select the Local option.Then you can click the button to start the connection process.

Once connected, you can navigate to the containers section which lists all existing Docker containers.This includes also Docker containers which where created using the Synology Docker user interface.

Please be aware that the Docker containers won’t show up anymore in the Synology user interface once you modified an existing Docker container with Portainer.Also, all Docker containers created by Portainer won’t show up in the Synology user interface.

With the Portainer setup described here, you have an alternative to manage Docker containers on a Synology NAS.Using Portainer offers access to all Docker features - not just the limited feature set provided by the Synology user interface.

As a follow up to my previous post as curiosity got the better of me. I decided to see how difficult it would be to set up MariaDB/Grafana/NodeRED on my Synology 1815+. Come to find out it is not that difficult to do so once you figure out the quirks of the UI you have to use.

Here is how to setup docker like I have but in a Synology system.

Synology Docker Image File

Install Docker

First thing, install docker if you do not have it already installed. Open the package center and in the third party apps section.

Open Package Center
Find and install Docker under Third Party
Open Docker

Pull down the images

Once you have the docker window open you will need to pull down the container images. To start go to registry, and search an image. Below is a short list of image:tag to search and work with.

  • nodered/node-red:latest
  • grafana/grafana:latest
  • linuxserver/mariadb:latest
    • “Official” is mariadb:latest, but linuxserver team does a good job with their images

Example search node-red and you should find nodered/node-red in the list. Click it, then click the little popout icon to go to the page and see if there are any listed environment variables you might need/want to set. Then click download. Repeat for all 3 images.

Wait till all images download

Go to the images section and wait till all images have a size of greater than 0 MB.

Configure and start MariaDB

Once the images all have a file size it is time to launch them, starting with mariadb. In the images section highlight the chosen image, in this case linuxserver/mariadb:latest, then click the little pop out arrow icon. Switch back to the Synology window and click Launch.

Now you are given a chance to edit the settings for it. The tabs of main interest are the volumes and environment tabls. Under volumes click add folder and proceed to make a new structure of docker/mariadb/data, once you have that choose the data folder. Map it to /data. In the environment tab these are optional but suggested, add an entry for TZ, aka timezone, and set it to the local timezone if that is desired, mine is American/New_York. The other setting is MYSQL_ROOT_PASSWORD, set put a password you want the root user to have.

You may also want to have this container auto-restart, that is under Advanced Settings. You may (recommended for now) also want to forward through the port from the Synology’s IP address. Under Port Settings change the local port from Auto to 3306.

Details of interest in the new window that gets opened.
Images, highlight, open details, Launch
Advanced Settings

Folder Structure
Configure Volumes
Configure Environmental

The other environment variables that can be set can be found in new window that was opened.

Once done you can click apply and next and apply.

Configure and start Grafana

Launch the grafana/grafana:latest image like the MariaDB was. This time you want to map the volumes as follows:

  • docker/grafana/logs -> /var/log/grafana
  • docker/grafana/data -> /var/lib/grafana
Synology

Docker Synology Update Image

If you want to map the port through, the port is 3000.

Configure and start NodeRED

NodeRED volumes

Launch the grafana/grafana:latest image like the MariaDB was. This time you want to map the volumes as follows:

  • docker/nodered/data -> /data

Fix filesystem permissions the lazy way

Set everyone to Read and Write and apply to subfolders

At this point, there should be a couple of containers crashing. If you dig in you will see the logs indicate that they are trying to copy data to the configured volume mount points. They can not due to permissions of where the volumes are on the Synology volume.

The lazy answer here is to edit the docker folder, give read/write to everyone with an application to all subfolders.

Verify they are running…

Docker Hub

At this point, NodeRED, Grafana, and MariaDB should be running without issue.

Synology Docker Image Location

Grafana will be at http://<ipaddress>:3000/ and the default login is admin/admin.

What Is Docker

NodeRED will be at http://<ipaddress>:1880/ and has no login by default.

For MariaDB, you can pull up a console and interact with it via a bash prompt. To do that:

Synology Docker Image Download

  • Go to the container section
  • Click on the mariadb container
  • Click details up top, new window pops open
  • Click terminal in the new window
  • Click create
  • A new line appears on left side labeled “bash”, click it
  • You now have a root prompt into the container,
  • mysql -u root -p
    • Enter the password you set as the environment variable

Most Viewed Posts