I had previously been running my side project websites and projects on a Windows Home Server HP Microserver. It served e very well for years but was not having a bit of trouble keeping up with HD videos and was getting a bit noisy.
I decided it was a good candidate for another Covid Project.
The microserver served three functions:
- Host for a couple of websites
I decided to split out the HTPC aspect a get a specific mini pc for that and get a NAS for well the NAS. I hadn't really decided on where to host the websites but was I think at the time expecting to run it on the mini-pc.
Once I set up the NAS it turned out it supports Docker and it seems like a fun way to go. It also meant I could keep the min-pc clutter free without a load of dev tools.
My existing set up was an nginx instance in front of any of the other sites I had running at the time, the main site being this blog.
There were both Nginx and Ghost images available so this seemed like a sensible way to go.
The first thing to set up is the Container Station. This can be installed via the App Store. There are plenty of useful documentation online such as: How to use Container Station? | QNAP Container Station | Supports LXC and Docker containers | QNAP
One of the things I found confusing about Container Station was how to actually install an image. My go to was to search for the image and click install, and while this works, I don't think this is how it's expected to be used.
Using the "Create Application" option, while more daunting, gives a much better experience overall. The only drawback being that you have to spend a bit of time getting to know Docker compose.
On clicking this you are presented with the following screen:
The most important thing to notice here is the link to Overview of Docker Compose | Docker Documentation
I would recommend using this even for single image set up because configuring them via docker compose is much simpler. There is no way to edit a image that is installed directly.
Set up Nginx
So there are 2 main steps to setting up the NGIX instance.
- Set up the container
There are 2 parts to this, setting up the env variables and the volumes. The volumes are important because you need to be able to provide configuration of the instance. The nginx image defaults to loading html and config from certain locations. You can provide a path to a location on your NAS and mount this in the container. See the volumes section:
version: '3' services: nginx: image: nginx:latest restart: always ports: - 443:443 volumes: - /path/to/html:/usr/share/nginx/html - /path/to/nginx/config:/etc/nginx environment: NGINX_VERSION: 1.19.5 NJS_VERSION: 0.4.4 PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PKG_RELEASE: 1~buster
- Note that your NAS shares are located in `/share`
2. Set up the nginx config
I'm not going to go through this, this is really up to your own specific application. I will discuss how to route traffic to another container later.
Set up Ghost
Setting up Ghost was pretty trivial using the provided image, instructions are available here ghost - Docker Hub. I did try an install the mysql db with it but it doesn't work by the NAS I have is using an ARM processor and there is no mysql image for ARM. I removed that and went with sqllite.
version: '3' services: ghost: image: ghost:3-alpine restart: always ports: - 2368:2368 environment: # this url value is just an example, and is likely wrong for your environment! url: http://localhost:2368
- Ghost sets up a permanent volume for itself to store content etc
The Hard Part
It was all going pretty smooth up to this point I could hit the ghost app and the nginx app. Unfortunately I could not hit the ghost app via the nginx app.
I spent a lot of time investigating this, restarting the containers, changing ports, updating the url of the ghost app, etc. All to no avail. I could hit either app separately but they could not see each other. I realised of course that the containers were running on their own networks and could not see each other.
This is made clear by the "Network and Virtual Switch" settings in QNP. There could see individual Virtual Adapters and Virtual Switches set up for the containers.
I tried a number of things via the docker compose configs that I think should have worked but didn't.
At the end of the day I ran some docker commands directly on the machine (via SSH which wasn't really obvious to me either, I figured there would be something on the NAS for doing that too).
docker network create <new network name> docker network disconnect <old default network name> <container-name> docker network connect <new network name> <container-name>
Do this for your containers, then check the "Network and Virtual Switch" again an take note of the IP of the Virtual Adapter. In my case I had to update by mginx config to use this IP to talk to the Ghost instance,