This can be done in two ways 1) with out creating docker image 2) creating docker image from the published folder
3) create image and download it from azure container registry
Approach 1: Without creating Docker image
Basic steps to host a .net core application on azure linux mahince with nginx
1. Create a resource group
2. Create a Linux virtual machine on azure. (may be ubutu server). Make sure port:80 is open as we are going to use it for http request.
3. Login to Linux virtual machine using PUTTY.
4. Install Docker
sudo apt install docker-ce
5. download nginx docker image
docker pull nginx:1.17.0
6. check if new downloaded image is avalible or not
docker images
7. Run default page of nginx. This will launch the default page of welcome to docker
docker run -d -p 80:80 nginx:1.17.0
--- from here approach 2 can be used ---------
8. install .net core SDK on linux vm
9. publish the .net core code from Visual studio locally and copy the publish folder from local to VM using WINSCP tool
10. run application on linum vm using .net core. it will run kestral web server by default.
dotnet projectfile.dll
11. Now we have to configure nginx configuration file to transafer all request to kestral server and we will hit nginx port to access application.
Approach 2: creating docker image from the published folder
1. create a docker file and write below content into it.
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 -- this tell the default image to take reference
WORKDIR /app -- working directory for ur application
COPY . . -- copy from publish folder to working directory
ENV ASPNETCORE_URLS http://*:5000 -- open the port
EXPOSE 5000
ENTRYPOINT ["dotnet", "coreproj.dll"] -- dotnet application with applicpation name as 'coreproj'
2. Run following command. this command will run the above file
sudo docker build -t dotnetapp .
3. Run the application
sudo docker run -d -p 5000:5000 dotnetapp
Since here we are mentioning 5000 we have to open inbound port for 5000 as well.
4. Stop the application
sudo docker stop dotnetapp
No comments:
Post a Comment