Saturday, January 18, 2020

CREATE MICROSERVICE WITH .NETCORE

WHAT IS THE SOFTWARE REQUIRED FOR WINDOWS?

ØWindows 10 is required for Docker installation.
ØVisual Studio 2017 has built-in support for Docker, so this is highly recommended.
Ø.NET Core SDK
ØDocker for Windows
ØDocker Tools

Demo


ØCreate a .netcore web API with docker support





ØI got a application with below structure




Ø  Open Application folder from command prompt and check the existing
images using Docker images and running containers using Docker PS.
Image:

Container:

ØAlready I have above images.now I have created new image.

To build the image:

 docker build -t learndokcer .
Finally, I have created an image successfully. my image name is learndocker(here, in the screenshot I mentioned the image name wrongly.)





Again,I check my images


Run the image in a container: 

docker run -d -p 15001:80 --name dc1 learndokcer






docker run -d -p 15002:80 --env ASPNETCORE_ENVIRONMENT-QA --name dc2 learndokcer


Check the docker container

dc1 container


dc2 container




Docker File Explanation:


FROM:


    It tells docker, from which base image you want to base your image from. In our example, we are creating an image from the aspnetcore image. 

RUN :


the command is used to run instructions against the image.


WORKDIR /app:


WORKDIR /app is the working directory of the image; it will store all DLLs inside the app folder.

Copy:


COPY will copy the DLLs of the application to the root directory (here dot represents the root) of the image.


ENTRYPOINT


ENTRYPOINT is responsible to run the main application with the help of ASPNETCOREAPP.dll.


Push and pull the image using docker hub registry


Push image


Ødocker login

Ødocker tag b0887ae04e85 arulpushpam/boardservice:version-1

b0887ae04e85 -image id
Arulpushpam-yourhubusername
Boardservice - image name
version-1 - tage name

Ødocker push arulpushpam/boardservice

Pull image


Ødocker pull arulpushpam/boardservice:version-1

Faced issues

Issue 1:


I got this issue while run the docker image


Reason:

Firewall blocked.we cant get the nuget source file while doing dotnet restore

Solution:            

Using this docker file for creating an image

Step 1:

Publish the files to this folder bin/Release/netcoreapp2.1/publish

Step 2:

Create a docker file


FROM microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-1709 AS base
FROM microsoft/dotnet:2.1-sdk-nanoserver-1709  AS build
WORKDIR /app
COPY bin/Release/netcoreapp2.1/publish .
ENTRYPOINT ["dotnet", "/app/BoardService.api.dll"]


Issue 2:

Issue changing the docker file

   While running my application I got a build error and below prompt




Solution:

  It is like a syntax error.when we use any unnecessary lines in the docker file after we got those errors.if we follow the syntax we resolve this.
   

2)while building image 

Issue 3:


Solution

1. Right-click Docker instance
2. Go to Settings
3. Daemon
4. Advanced
5. Set the "experimental": true
6. Restart Docker

Issue 4:


 Solution
move my Dockerfile to the root folder (where exists .sln and .dockerignore files) and my problem was resolved.

Issue 5:


Solution

1. Stop service docker
2. Stop service HNS
3. Delete "C:\ProgramData\Microsoft\Windows\HNS\HNS.data"
4. Delete "C:\ProgramData\docker\network\files\local-kv.db"
5. Start service HNS
6. Start docker

Issue 6:


Solution

In powershell
cd "C:\Program Files\Docker\Docker"
./DockerCli.exe -SwitchDaemon


Sample code
   https://github.com/ArulPushpam/Docker/

No comments:

Post a Comment