Now I’ve got the Synology NAS up and running, I thought it would be interesting to see what the Docker support is like. You can essentially run Docker container instances on the NAS box which also means you can deploy your own custom .NET Core apps to the Synology box.
This post is organized into 3 parts:
- Creating and testing a Docker-enabled ASP.NET Core app locally
- Deploying the app to the Synology NAS via Docker Hub
- Deploying the app locally to the NAS
Part 1: Creating and Testing a Docker ASP.NET Core App Locally
There’s a few things to setup to allow you to deploy and Test Docker containers locally.
The first is to enable Hyper-V in Windows, this is a prerequisite of Docker Desktop for Windows:
Once you’ve enabled Hyper-V (a restart will probably be required) you can go and download and install Docker Desktop for Windows – this will allow you to enable Docker support when you create the project in Visual Studio.
Once Docker Desktop is installed and running you can check it’s running with PowerShell:
PS C:\Users\Admin> docker version
Client: Docker Engine - Community
API version: 1.40
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:23:10 2020
Server: Docker Engine - Community
API version: 1.40 (minimum version 1.12)
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:29:16 2020
Now you can fire up Visual Studio and create a new ASP.NET Core web application and tick the Enable Docker Support checkbox:
Once the project is created, you can click the Run button in Visual Studio (it should say “Docker” next to it).
Checking the Output window for Container Tools you should can see something like:
========== Checking for Container Prerequisites ==========
Verifying that Docker Desktop is installed...
Docker Desktop is installed.
========== Verifying that Docker Desktop is running... ==========
Verifying that Docker Desktop is running...
Docker Desktop is running.
========== Verifying Docker OS ==========
Verifying that Docker Desktop's operating system mode matches the project's target operating system...
Docker Desktop's operating system mode matches the project's target operating system.
========== Pulling Required Images ==========
Checking for missing Docker images...
Pulling Docker images. To cancel this download, close the command prompt window.
docker pull mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim
After a while the build might fail with the following error: Error CTC1001 Volume sharing is not enabled. On the Settings screen in Docker Desktop, click Shared Drives, and select the drive(s) containing your project files.
To fix this, open up the Docker Desktop UI, and find the File Sharing section and enable C: drive if you want to make it available to Docker – this should fix the error:
Once this this change is applied and Docker Desktop restarted, click the Start button again in Visual Studio and after accepting dialog boxes to do with firewall and local certificate the web app should start up and run successfully and Docker Desktop should show the web app container running:
So now you have a Docker-enabled .NET Core web app and have tested it locally you can deploy it to the Synology NAS.
Part 2: Deploying an ASP.NET Core Docker App To a Synology NAS Via Docker Hub (AKA There And Back Again – a Docker Hub Tale)
Docker Hub is place (“registry”) where you can store and manage Docker images. These images can then be pulled (downloaded) by a Docker host and then a container started from this image.
Visual Studio has built-in support for pushing an image to Docker Hub and the Synology Docker app has the ability to pull images from Docker Hub. Images on Docker Hub can be public or private (depending on what plan you are using).
Once you’ve created a Docker Hub account, in Visual Studio go to the Build menu and choose Publish WebApplication1 (or whatever the name of your project is) and click Start. You will need to choose a publish target of Container Registry and choose Docker Hub:
Click Create Profile - you’ll need to supply your Docker Hub user name and password and click save.
You can now click the Publish button and wait for a little while:
You should see the app being pushed to Docker Hub:
Once the publish is complete you can head over to Docker Hub and you should see your image:
Now the image is in Docker Hub, you can enable Docker support on the Synology NAS, pull the image from Docker Hub, and start a container on the NAS.
First log into the Synology as an admin account and open the Package Center. Here you can search for “Docker” and install the Docker app:
Once you’ve installed the Docker app, open it and head to the Image section, click the Add button and choose Add From Url. Now you can head over to Docker Hub and copy the URL for your image, for example it will look something like this: https://hub.docker.com/r/jrdontcodetired/webapplication1:
Click Add and the image will be downloaded from Docker Hub to the NAS.
Once the image has downloaded, click on it and click the Launch button. This will enable you to start a container instance from the image.
You’ll need to click on Advanced Settings and go to the Port Settings tab. In the Dockerfile in Visual Studio, the image is set to use port 80. We need to map a port on the NAS to this port 80 in the container. For example you could set up port 7500 on the NAS itself to map traffic to port 80 in the container:
Click Apply and then Next. You will be given a summary of the settings (the “Run this container after the wizard is finished” box is ticked) and click Apply to finish the wizard and start the container.
You should now be able to see the container running in the Container section:
You can now point your browser to your NAS IP and the port your chose when staring the container, for example: http://192.168.20.17:7500/
You should now see your ASP.NET Core web app being served from the Docker container on the Synology NAS:
Part 3: Directly Deploying Docker Container to a Synology NAS
The first step is to publish the web app and copy the published files to the Synology. You could also publish directly to a folder on the NAS such as: \\SYN001\Test1\DockerPublish
In Visual Studio from the Build menu choose Publish WebApplication1. Create a new Publish Profile this time using a Folder Target and as the folder choose a folder on the Synology:
Click Create Profile and then click Publish. Once this is finished you should see the web app files published to the Synology folder.
In the DockerPublish folder (this is an arbitrary name) on the NAS create a new Dockerfile with the following contents:
COPY . /app
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
Your folder on the Synology should now look like something like this:
The next step is to build the Docker image on the Synology NAS. To do this you can SSH into the NAS and use Docker build.
The first step is to enable SSH access on the Synology, you can do this from the Synology Control Panel in the Terminal & SNMP section – tick the Enable SSH Service box and click Apply:
Next in Windows, open a new PowerShell window and enter:
Replace “Jason” with the name of one of your admin users and the IP address with the address of your Synology NAS – you will then need to enter the user’s password.
We need to SSH in as root (or set up a new user on the NAS). Be careful working in root or you could seriously mess your NAS up or introduce security problems. To get root access enter:
And once again enter the password.
You can now change to the folder that contains the published web app and Dockerfile:
And now build the image:
docker build -t manualwebapp .
This will produce the following output:
Sending build context to Docker daemon 4.706MB
Step 1/5 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim
3.1-buster-slim: Pulling from dotnet/core/aspnet
c499e6d256d6: Pull complete
251bcd0af921: Pull complete
852994ba072a: Pull complete
f64c6405f94b: Pull complete
9347e53e1c3a: Pull complete
Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim
Step 2/5 : COPY . /app
Step 3/5 : WORKDIR /app
---> Running in e731c0fa1d6e
Removing intermediate container e731c0fa1d6e
Step 4/5 : EXPOSE 80
---> Running in 6fddd1f77f4e
Removing intermediate container 6fddd1f77f4e
Step 5/5 : ENTRYPOINT ["dotnet", "WebApplication1.dll"]
---> Running in 4f0b086e44d3
Removing intermediate container 4f0b086e44d3
Successfully built ead6395bf486
Successfully tagged manualwebapp:latest
If you now head to the Docker app on the Synology you will see the manualwebapp image:
You can start a container from this image as we did before using the Synology GUI or from the PowerShell prompt - we can start it with the following command (notice we’re mapping port 7501 on the NAS to port 80 in the container):
docker run --name manualtestcontainer -p 7501:80 -d manualwebapp
Now heading back the the Synology GUI you should see a container called manualtestcontainer running:
Now you can head to the URL in a browser (e.g. http://192.168.20.17:7501/) and see the ASP.NET Core web app running in the Docker container:
The ability to run Docker containers on a NAS is really nice, not only can you develop your own apps and deploy them as containers, you can also use images from a registry such as Docker Hub, for example MySQL, ghost blogging engine, etc. You should of course only use images you trust.
If you have any cool containers running on your Synology let me know in the comments!