Synology NAS is a powerful NAS and it can support docker, so we can do a lot of things with it. If you want to deploy your asp.net core 2.0 to synology, that will be easy with docker.
Using the code
I use the Mac os, so I will use visual studio 2017 for Mac for create the asp.net core 2.0 project.
- Create a new asp.net core 2.0 mvc project and name with “HelloWorld”
- Because visual studio 2017 for Mac can’t publish the project directly, so we need to go to the project folder and run below command for release the project:
dotnet publish -c Release
After that you will get the release file in your project bin folder : /bin/Release/netcoreapp2.0/publish/
- Copy all of the /bin/Release/netcoreapp2.0/publish/ files to your nas driver, for example: /volume1/web/asp_net_core/helloworld
- Install the asp.net core 2.0 image in docker, you can use “microsoft/aspnetcore“, and select 2.0 version:
- And then you will find a new image as below and name : “microsoft/aspnetcore:2.0.0“
- Create a file name “Dockerfile” without file extension. It is a kind of batch file with Docker commands. The file is needed during the image build process. You can create the file with any text editor you like. Save the file in your project folder. for example: /volume1/web/asp_net_core/helloworld . Please find below content of this file:
FROM microsoft/aspnetcore:2.0.0 COPY . /app WORKDIR /app ENV ASPNETCORE_URLS http://*:7500 EXPOSE 7500 ENTRYPOINT ["dotnet", "HelloWorld.dll"]
The Dockerfile execute several important steps :
- microsoft/aspnetcore:2.0.0 will be used for the helloword image.
- Sets the HelloWorld files location.
- Sets application IP port.
- Sets application entry point.
- Login your nas with ssh and go to your project folder and run below command for create the docker image:
docker build -t helloworld .
You will find there is a new image as below, and click “Launch”
- Set the image’s port to 7500 (same with your Dockerfile setting)
- And it will create a new container as below:
- Now you should can access your website with your nas ip, for example: http://192.168.0.20:7500
If you have a public domain and want to public your website, you can add a reverse proxy in your nas:
90,253 total views, 34 views today