Saturday, 17 October 2020

                           Pushing your asp.net core application to under docker


Step1 create dotnet core application as structure below by name Myapp2


step 2 Now create the docker file under the project without any  extension and also create the .dockerignore file 

step 3  now our project working directory would be like the below ,where we put docker file and .dockerignore file


step 4 now under the dockerfile write the below code so that required things install  in docker container


FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /Myapp2
# copy csproj and restore as distinct layers
COPY *.sln .
COPY Myapp2/*.csproj ./Myapp2/
RUN dotnet restore

# copy everything else and build app
COPY Myapp2/. ./Myapp2/
RUN dotnet publish -c Release -o out


FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime
WORKDIR /Myapp2/Myapp2
COPY --from=build /Myapp2/out ./
ENTRYPOINT ["dotnet", "Myapp2.dll"]

step 5 now use the .dockerignore file mentioned the below code under it so that those folders get ignore 


# directories
**/bin/
**/obj/


step 6 now come to the working directory Myapp2 on cmd  and run the build command 


docker build -t myapp2:v1 .






now you can see our docker build command success and image has created 



step 7 Now create the container by using the below command as per our application

docker run -d -p 8080:80 --name mycoreconatiner myaap2:v2



step 8 use this command to find the ip of running container means ip address ,

docker inspect mycoreconatiner


now you can see our application running on the below ip address




now do the request of this url(http://172.27.59.53/weatherforecast) on browser then our application will run as below












No comments:

Post a Comment