How to deploy asp.net core 2.0 to synology NAS

Introduction

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.

    1. Create a new asp.net core 2.0 mvc project and name with “HelloWorld”
    2. 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:
    3. dotnet publish -c Release

      After that you will get the release file in your project bin folder :  /bin/Release/netcoreapp2.0/publish/

    4. Copy all of the /bin/Release/netcoreapp2.0/publish/ files to your nas driver, for example:  /volume1/web/asp_net_core/helloworld
    5. Install the asp.net core 2.0 image in docker, you can use “microsoft/aspnetcore“, and select 2.0 version:
    6. And then you will find a new image as below and name : “microsoft/aspnetcore:2.0.0
    7. 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:
    8. 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 :

      1. microsoft/aspnetcore:2.0.0 will be used for the helloword image.
      2. Sets the HelloWorld files location.
      3. Sets application IP port.
      4. Sets application entry point.
    9. Login your nas with ssh and go to your project folder and run below command for create the docker image:
    10. docker build -t helloworld .

      You will find there is a new image as below, and click “Launch”

    11. Set the image’s port to 7500 (same with your Dockerfile setting)
    12. And it will create a new container as below:
    13. 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:

    1. Create a reverse proxy in nas  Control Panel -> Application Portal
    2. Fill below information with the reverse proxy
    3. After that, you will can access your asp.net core website with your public domain 🙂
  1.  

     

70,215 total views, 71 views today

Do you like this post?
  • Fascinated
  • Happy
  • Sad
  • Angry
  • Bored
  • Afraid

winson

Leave a Reply

coder-blog-1
shares