how to

Setting up Synology NAS as a Git Server

Running Docker containers on a NAS device has given me permission to invest more in experimentation.

Written by Theodora · 2 min read >
Git icon

I purchased a Synology NAS device in November, 2022 primarily for storing photos from my Android phone and my husband’s iPhone to break the cycle of endless Cloud storage fees. 3 years later I’m finally expanding its usage to include things that I would usually host on my desktop.

Synology NAS

Truth be told, I saw NAS devices just as glorified external drives with a lightweight Linux OS for management. I forgot what article I was reading when I learned these things could run Docker containers! I’m now dusting the cobwebs off several projects that I hope to blog about, starting with somewhere to store all that code.

I did a bit of research before deciding on Gitea, primarily because it is super lightweight—my NAS is geared for storage, not computing. I relied on the tutorials from mariushosting.com and got everything set up in… about two weeks—#thatmomlife.

Here’s everything I had to do to get it running.

Setup a wildcard certificate*.<my-sub-domain>.synology.me

Synology offers a free (sub-domain) certificates with a registered Synology account plus wildcard certificate for all sub-sub domains and a DDNS service to auto update the. They also handle the certificate autorenewals every three months. This means that I can register theodora.synology.me and then host any Docker container in my NAS like Gitea, Portainer, or MyCustomSecureService, and have a secure URL that works perfectly.


Of course a custom domain could be used (e.g. gitea.theodoradule.com), but since none of my services will be exposed to the internet, this was a good enough option for my needs.

Install Portainer – easy management of docker containers

I wasn’t sure how much effort Portainer would actually save me, but it proved worthwhile for deleting, restarting and modifying docker-compose files easily in a GUI. I could not get the command line terminal to work, and had to ssh into the NAS and run docker commands when diagnosing issues. I image when I have dozens of containers to manage, it’ll be more useful, but jury’s still out.

Finally, install Gitea – from a docker-compose.yaml file

Next step is to create a stack in Portainer to setup a PostGreSql container and Gitea container with associated volumes in the NAS file system. This is where I lost a lot of time debugging because of an error in the tutorial and some missing configurations in the NAS that would have been there by default on a regular desktop docker installation.

Getting setup for debugging

When things don’t go right after following the tutorials, it was necessary to return to the terminal to run commands myself. You’ll need to open a terminal window from your desktop, then ssh into the NAS device.

If ssh doesn’t work…

Make sure ssh is enabled.

If running docker commands on the terminal doesn’t work

Here the issue on my Synology NAS was that the docker group did not exist, and my non-root user did not have access to docker.sock

sudo synogroup --add docker
sudo chown root:docker /var/run/docker.sock
sudo synogroup --member docker <your-non-root-account>

If you get a 500 error when creating a new repository

After the positive vibes getting all my setup working, I was disappointed to get this error when creating my first repository.

It was especially frustrating because the error points to a permissions issue, which I chased to the ends of the earth, double checking the user inside the container, trying the command myself as root, and every permutation in between. The actual issue turned out to be an incorrect mapping in the docker compose file where two different paths were mounted to the same source folder.

There was an interesting cyclical reference when trying to create a folder inside the repositories folder.

volumes:
      - /volume1/docker/gitea/data:/data:rw
      - /volume1/docker/gitea/data:/data/git/repositories:rw

Once I commented out the second line, we were golden.

Now that I have Gitea working, I can create a repository and start pushing code to it. So, what’s next to further this experiment along?

  • Connect to Gitea on my desktop from SourceTree or GitHub Desktop
  • Set up pgAdmin on my desktop to connect to the Gitea Postgres database container
  • Replace PostgreSql with MS SQL Server and setup Gitea again
  • Set up alerting in Portainer