[{"data":1,"prerenderedAt":575},["ShallowReactive",2],{"i-mdi:theme-light-dark":3,"i-mdi:menu":8,"i-mdi:linkedin":10,"i-mdi:github":12,"i-mdi:email-outline":14,"article-\u002Farticles\u002Fstart-with-docker-2-first-dot-net-core-container":16,"i-mdi:arrow-left":573},{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":7},0,24,false,"\u003Cpath fill=\"currentColor\" d=\"M7.5 2c-1.79 1.15-3 3.18-3 5.5s1.21 4.35 3.03 5.5C4.46 13 2 10.54 2 7.5A5.5 5.5 0 0 1 7.5 2m11.57 1.5l1.43 1.43L4.93 20.5L3.5 19.07zm-6.18 2.43L11.41 5L9.97 6l.42-1.7L9 3.24l1.75-.12l.58-1.65L12 3.1l1.73.03l-1.35 1.13zm-3.3 3.61l-1.16-.73l-1.12.78l.34-1.32l-1.09-.83l1.36-.09l.45-1.29l.51 1.27l1.36.03l-1.05.87zM19 13.5a5.5 5.5 0 0 1-5.5 5.5c-1.22 0-2.35-.4-3.26-1.07l7.69-7.69c.67.91 1.07 2.04 1.07 3.26m-4.4 6.58l2.77-1.15l-.24 3.35zm4.33-2.7l1.15-2.77l2.2 2.54zm1.15-4.96l-1.14-2.78l3.34.24zM9.63 18.93l2.77 1.15l-2.53 2.19z\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":9},"\u003Cpath fill=\"currentColor\" d=\"M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":11},"\u003Cpath fill=\"currentColor\" d=\"M19 3a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2zm-.5 15.5v-5.3a3.26 3.26 0 0 0-3.26-3.26c-.85 0-1.84.52-2.32 1.3v-1.11h-2.79v8.37h2.79v-4.93c0-.77.62-1.4 1.39-1.4a1.4 1.4 0 0 1 1.4 1.4v4.93zM6.88 8.56a1.68 1.68 0 0 0 1.68-1.68c0-.93-.75-1.69-1.68-1.69a1.69 1.69 0 0 0-1.69 1.69c0 .93.76 1.68 1.69 1.68m1.39 9.94v-8.37H5.5v8.37z\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":13},"\u003Cpath fill=\"currentColor\" d=\"M12 2A10 10 0 0 0 2 12c0 4.42 2.87 8.17 6.84 9.5c.5.08.66-.23.66-.5v-1.69c-2.77.6-3.36-1.34-3.36-1.34c-.46-1.16-1.11-1.47-1.11-1.47c-.91-.62.07-.6.07-.6c1 .07 1.53 1.03 1.53 1.03c.87 1.52 2.34 1.07 2.91.83c.09-.65.35-1.09.63-1.34c-2.22-.25-4.55-1.11-4.55-4.92c0-1.11.38-2 1.03-2.71c-.1-.25-.45-1.29.1-2.64c0 0 .84-.27 2.75 1.02c.79-.22 1.65-.33 2.5-.33s1.71.11 2.5.33c1.91-1.29 2.75-1.02 2.75-1.02c.55 1.35.2 2.39.1 2.64c.65.71 1.03 1.6 1.03 2.71c0 3.82-2.34 4.66-4.57 4.91c.36.31.69.92.69 1.85V21c0 .27.16.59.67.5C19.14 20.16 22 16.42 22 12A10 10 0 0 0 12 2\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":15},"\u003Cpath fill=\"currentColor\" d=\"M22 6c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2zm-2 0l-8 5l-8-5zm0 12H4V8l8 5l8-5z\"\u002F>",{"id":17,"title":18,"body":19,"category":50,"description":559,"extension":560,"meta":561,"navigation":562,"path":563,"published":564,"seo":565,"stem":566,"tags":567,"__hash__":572},"articles\u002Farticles\u002Fstart-with-docker-2-first-dot-net-core-container.md","Start with Docker part 2 - First .NET Core Container",{"type":20,"value":21,"toc":544},"minimark",[22,27,52,56,81,86,130,134,152,159,178,182,248,253,267,271,316,321,330,407,414,418,422,431,434,446,464,471,476,490,495,499,528,532],[23,24,26],"h2",{"id":25},"small-review","Small Review",[28,29,30,31,38,39,43,44,47,48,51],"p",{},"In the ",[32,33,37],"a",{"href":34,"rel":35},"https:\u002F\u002Fblog.dawidstefaniak.com\u002Fprofessional\u002Fdocker\u002Fstart-with-docker\u002F",[36],"nofollow","previous tutorial",", we learned ",[40,41,42],"strong",{},"basic concepts"," of working with Docker. This tutorial will focus on creating and deploying basic console ",[40,45,46],{},".NET Core 2.1 application"," into the ",[40,49,50],{},"Docker"," container. We will also try to interact with our new container sending some stdin to it.",[23,53,55],{"id":54},"lets-prepare","Let's prepare!",[28,57,58,59,62,63,66,67,70,71,76,77,80],{},"Through the whole tutorial, I will be using ",[40,60,61],{},"Visual Studio Code"," as a code editor. Let's create a new project called ",[40,64,65],{},"\"DockerTutorial1.1\"",". To create ",[40,68,69],{},"new C# .NET Core 2.1"," project in Visual Studio code, simply ",[32,72,75],{"href":73,"rel":74},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Fdotnet\u002Fcore\u002Ftutorials\u002Fwith-visual-studio-code",[36],"follow the tutorial",". If you are using Visual Studio for Windows, Create new .NET Core Console Application. To check if our project uses .NET Core 2.1, ",[40,78,79],{},"open DockerTutorial1.1.csproj",".",[82,83,85],"h3",{"id":84},"in-visual-studio-for-windows","In Visual Studio for Windows:",[87,88,89,99,109],"ol",{},[90,91,92,95,96],"li",{},[40,93,94],{},"Right click"," on your project in solution explorer and select ",[40,97,98],{},"Unload Project",[90,100,101,104,105,108],{},[40,102,103],{},"Right-click"," on the project (tagged as unavailable in solution explorer) and click ",[40,106,107],{},"\"Edit DockerTutorial1.1.csproj\"",". This will open up your CSPROJ file for editing.",[90,110,111,114,115,118,119,122,123,125,126,129],{},[40,112,113],{},"After making"," any ",[40,116,117],{},"changes"," you want, ",[40,120,121],{},"save"," and close the file. ",[40,124,103],{}," again on the node and choose ",[40,127,128],{},"Reload Project"," when done.",[82,131,133],{"id":132},"in-visual-studio-code","In Visual Studio Code:",[28,135,136,139,140,143,144,147,148,151],{},[40,137,138],{},"Click"," on ",[40,141,142],{},"DockerTutorial1.1.csproj"," in the ",[40,145,146],{},"Explorer",". The ",[40,149,150],{},"output"," should be similar to that:",[28,153,154],{},[155,156],"img",{"alt":157,"src":158},"Docker Tutorial 2","\u002Fimages\u002F6\u002Fdocker2.1.png",[28,160,161,162,165,166,169,170,174,175],{},"If ",[40,163,164],{},"TargetFramework"," is pointing to the version ",[40,167,168],{},"2.1 of .NET Core",", you are on the right way. If it's not, just simply change the version to 2.1 and use ",[171,172,173],"code",{},"dotnet restore"," command. ",[171,176,177],{},"NOTE: Remember to [install .NET Core 2.1 SDK](https:\u002F\u002Fwww.microsoft.com\u002Fnet\u002Fdownload\u002Fwindows) before starting",[23,179,181],{"id":180},"create-the-solution","Create the Solution",[28,183,184,185,188,189,192,193,196,197,200,201,204,205,208,209,212,213,216,217,208,220,223,224,227,228,231,232,235,236,239,240],{},"Let's create ",[40,186,187],{},".NET Core Console Application"," and run it in our System. The solution which we will prepare is quite small and it will have basic functionality like ",[40,190,191],{},"printing few strings"," ",[40,194,195],{},"of text"," and ",[40,198,199],{},"get some input"," from the user. Let's make our application ",[40,202,203],{},"print \"Hello\""," with the name taken from stdin and also ",[40,206,207],{},"print out"," the ",[40,210,211],{},"name"," of the ",[40,214,215],{},"environment"," to be sure that our solution is actually ",[40,218,219],{},"running on",[40,221,222],{},"Linux"," environment. Use ",[171,225,226],{},"dotnet run"," command to ",[40,229,230],{},"start"," the project in Visual Studio Code. In Visual Studio just simply click the ",[40,233,234],{},"run button",". The actual output can be seen in the picture below. Remember to ",[40,237,238],{},"always save"," the file before using dotnet run command. ",[40,241,242,243,80],{},"The project used in this example will be available on my ",[32,244,247],{"href":245,"rel":246},"https:\u002F\u002Fgithub.com\u002Fdawidstefaniak\u002FDockerTutorial1.1",[36],"GitHub",[28,249,250],{},[155,251],{"alt":157,"src":252},"\u002Fimages\u002F6\u002Fdocker2.2.png",[28,254,255,256,259,260,263,264],{},"In my case, ",[40,257,258],{},"MacOS"," is using Unix command line hence my OSVersion is ",[40,261,262],{},"Unix 17.6.0.0"," but in your case, it will probably show something ",[40,265,266],{},"different.",[23,268,270],{"id":269},"create-dockerfile","Create Dockerfile",[28,272,273,276,277,280,281,284,285,288,289,292,293,296,297,300,301,304,305,307,308,311,312,315],{},[40,274,275],{},"Dockerfile"," is a special file which gives our docker ",[40,278,279],{},"list of the instructions"," containing names of the images which will be used to ",[40,282,283],{},"create our container"," and also a list of the commands to ",[40,286,287],{},"run inside the container"," after creation. To create new Docker Image firstly, we have to ",[40,290,291],{},"create a new file"," in the solution folder named ",[40,294,295],{},"dockerfile"," (without any extension). To do it, ",[40,298,299],{},"right-click on the solution",", click ",[40,302,303],{},"add file"," and name it ",[40,306,295],{},". If you have ",[40,309,310],{},"Docker extension"," installed in VSCode (I highly recommend to do it), after opening the dockerfile, you will be able to see a nice small ",[40,313,314],{},"docker logo"," next to the file name.",[28,317,318],{},[155,319],{"alt":157,"src":320},"\u002Fimages\u002F6\u002Fdocker2.3.png",[322,323,325,326,329],"h4",{"id":324},"to-create-proper-dockerfile-we-have-to-learn-few-basic-commands","To create proper dockerfile we have to learn few basic ",[40,327,328],{},"commands",":",[331,332,333,353,363,389,401],"ul",{},[90,334,335,340,341,344,345,348,349],{},[40,336,337],{},[171,338,339],{},"FROM"," which is ",[40,342,343],{},"pointing on the image we want to use"," to create a new image. In our case, we will use ",[171,346,347],{},"microsoft\u002Fdotnet:2.1.300-sdk-stretch"," image which will give us the ability to build and run .NET Core 2.1 applications. ",[350,351,352],"em",{},"NOTE: This image is not appropriate for ASP.NET Core 2.1 Applications.",[90,354,355,340,360,80],{},[40,356,357],{},[171,358,359],{},"WORKDIR",[40,361,362],{},"changing the current directory to another",[90,364,365,373,374,380,381,384,385,388],{},[40,366,367,192,370],{},[171,368,369],{},"COPY",[171,371,372],{},"arg1 arg2"," which ",[40,375,376,377],{},"copies a file or whole directory from ",[171,378,379],{},"arg1"," which is our computer ",[40,382,383],{},"to arg2"," which is the directory inside the container. ",[40,386,387],{},"You can use"," '*' and '.' characters to select files with particular name or extension.",[90,390,391,396,397,400],{},[40,392,393],{},[171,394,395],{},"RUN"," is ",[40,398,399],{},"running command inside the container"," (in containers' terminal)",[90,402,403,406],{},[171,404,405],{},"**ENTRYPOINT**"," is pointing the file which has to be run when you start your container",[28,408,409,410,413],{},"Our ",[40,411,412],{},"final dockerfile"," should look as follow:",[415,416],"script",{"src":417},"https:\u002F\u002Fgist.github.com\u002Fdawidstefaniak\u002Ff7eebb79a26fd42b2b5ce9cf94e8743d.js",[23,419,421],{"id":420},"starting-new-docker-container","Starting new Docker Container",[28,423,424,425,196,428,80],{},"If our dockerfile is correctly formatted, we will be able to ",[40,426,427],{},"build the image",[40,429,430],{},"run a new container",[415,432],{"src":433},"https:\u002F\u002Fgist.github.com\u002Fdawidstefaniak\u002F4bbb821d1c7bdf6092f2db98714f4483.js",[28,435,436,437,440,441],{},"The ",[40,438,439],{},"naming convention"," for the docker image is ",[40,442,443],{},[350,444,445],{},"-creator-\u002F-name-: -tag-",[331,447,448],{},[90,449,450,455,456,459,460,463],{},[350,451,452],{},[40,453,454],{},"-it"," option gives information that our container will run in ",[40,457,458],{},"interactive mode",", what means that ",[40,461,462],{},"we can interact with our container"," using a terminal. Without using this option, our container will not react to any input from the user.",[28,465,466,467,470],{},"If everything went properly, we will be able to ",[40,468,469],{},"run"," our program in the container as same as we run it on our own computer.",[28,472,473],{},[155,474],{"alt":157,"src":475},"\u002Fimages\u002F6\u002Fdocker2.4.png",[28,477,478,481,482,485,486,489],{},[40,479,480],{},"The output"," displayed above presents that the version of Unix is 4.9.87.0 what means that ",[40,483,484],{},"our application is running inside the container",". To check a list of the images, we can use ",[350,487,488],{},"docker images"," command.",[28,491,492],{},[155,493],{"alt":157,"src":494},"\u002Fimages\u002F6\u002Fdocker2.5.png",[23,496,498],{"id":497},"summary","Summary",[28,500,501,502,505,506,509,510,512,513,516,517,520,521,524,525,80],{},"Docker is an ",[40,503,504],{},"awesome tool"," providing the environment for our strict needs which can be easily personalized. ",[40,507,508],{},"Everyone"," can use the same dockerfile to reconstruct exactly the same environment on every computer with ",[40,511,50],{}," installed. In the ",[40,514,515],{},"next tutorial",", I will make you familiar with ",[350,518,519],{},"ASP.NET Core 2.1"," applications running in Docker showing basic usage of ",[40,522,523],{},"porting"," and explanation how to create ",[40,526,527],{},".yaml configuration files",[23,529,531],{"id":530},"references-and-further-reading","References and further reading:",[28,533,534,539],{},[32,535,538],{"href":536,"rel":537},"https:\u002F\u002Fstackoverflow.com\u002Fquestions\u002F5129090\u002Fhow-to-edit-csproj-file",[36],"Editing csproj",[32,540,543],{"href":541,"rel":542},"https:\u002F\u002Fdocs.docker.com\u002Fengine\u002Freference\u002Fcommandline\u002Fdocker\u002F#child-commands",[36],"Docker commands",{"title":545,"searchDepth":546,"depth":546,"links":547},"",2,[548,549,554,555,556,557,558],{"id":25,"depth":546,"text":26},{"id":54,"depth":546,"text":55,"children":550},[551,553],{"id":84,"depth":552,"text":85},3,{"id":132,"depth":552,"text":133},{"id":180,"depth":546,"text":181},{"id":269,"depth":546,"text":270},{"id":420,"depth":546,"text":421},{"id":497,"depth":546,"text":498},{"id":530,"depth":546,"text":531},"In the previous tutorial, we learned basic concepts of working with Docker. This tutorial will focus on creating and deploying basic console .NET Core 2.1 application into the Docker container. We will also try to interact with our new container sending some stdin to it.","md",{},true,"\u002Farticles\u002Fstart-with-docker-2-first-dot-net-core-container",null,{"title":18,"description":559},"articles\u002Fstart-with-docker-2-first-dot-net-core-container",[50,568,569,570,275,571],"DevOps","Containers","Dockercompose",".NET Core","J0JTvqJ-3O4PKJuuOlX_OKVu0nGZuA0wit8B_U60598",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":574},"\u003Cpath fill=\"currentColor\" d=\"M20 11v2H8l5.5 5.5l-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5L8 11z\"\u002F>",1779997852660]