serving the solutions day and night

Pages

Sunday, August 16, 2020

ASP.NET Core Application with Docker

Create new ASP.NET Core MVC application through Visual Studio with Dockerfile.

OR Using Visual Studio Code, type "code .". Install the VSC extension named Docker by Microsoft, which help us to edit the Docker files.  

OR Create by .NET Core CLI

Create new folder c:\frontendmvc, use powershell to run the below commands

  • mkdir c:\frontendmvc
  • cd c:\frontendmvc
  • dotnet new mvc 
  • dotnet run

 

Create Dockerfile &  .dockerignore files 

 

Dockerfile -  Describe all the operations that want to execute to obtain a final Docker image. 

 

FROM instructs the Docker daemon to use the specified image to create a new image. If the image is not present locally, it's downloaded to local. 

WORKDIR - a working directory on the container to execute all forward commands based on a specific directory.

COPY  source under the image, copying all the content of the current directory in the app directory of the new image.  It copies all the contents of the current folder, including the bin and obj folders, exclude these folders using a Dockerignore file. 

RESTORE all project dependencies in the image 

       Run the docker build command to create image

 docker build -t frontendmvc .

 

Tag not specified, so latest is default tag

 

 Execute the command, a new docker container is created and run  

docker run -p 8080:80 -t frontendmvc

 

No comments: