=> CACHED RUN dotnet publish -c Release -o out 0.0s => load metadata for /dotnet/sdk:6.0 1.1s => load metadata for /dotnet/aspnet:6.0 0.8s => load build definition from Dockerfile 0.5s docker build -t counter-image -f Dockerfile. and when that command finishes, run docker images. NET runtime, you should still use the COMPlus_ prefix for environment variables.įrom your terminal, run docker build -t counter-image -f Dockerfile. If you're using a previous version of the. However, the COMPlus_ prefix will continue to work. NET 6 standardizes on the prefix DOTNET_ instead of COMPlus_ for environment variables that configure. When this command ends, the container will automatically stop. When the container starts, the ENTRYPOINT command runs. The next command, ENTRYPOINT, tells Docker to configure the container to run as an executable. The WORKDIR command changes the current directory inside of the container to app. In this example, the publish folder is copied to a folder named app in the container. The COPY command tells Docker to copy the specified folder on your computer to a folder in the container. The final steps of the Dockerfile are to create a container from the image and run the app, copy the published app to the container, and define the entry point. The 10 minutes ago is the time the image was created. The latest tag is the tag that is used to identify the image. The counter-image repository is the name of the image. After this command finishes, run docker images to see a list of images installed: docker imagesĬounter-image latest 2f15637dc1f6 10 minutes ago 208MB This command builds the image and creates a local repository named counter-image that points to that image. The -f switch is the path to the Dockerfile. in the docker build command sets the build context of the image. ĭocker will process each line in the Dockerfile. Some of the deeper-level files and folders have been omitted to save space in the article: ? docker-workingįrom your terminal, run the following command: docker build -t counter-image -f Dockerfile. The directory structure of the working folder should look like the following. NET 6.0 SDK and the base image referred to in the Dockerfile is tagged with 6.0. For example, the app created in the previous section used the. Make sure that you pull the runtime version that matches the runtime targeted by your SDK. The image is tagged with 6.0, which is used for versioning. The dotnet segment is the container repository, whereas the sdk or aspnet segment is the container image name.
The Microsoft Container Registry (MCR, ) is a syndicate of Docker Hub - which hosts publicly accessible containers. The FROM keyword requires a fully qualified Docker container image name. The ASP.NET Core runtime image is used intentionally here, although the /dotnet/runtime:6.0 image could have been used. FROM /dotnet/sdk:6.0 AS build-envĮNTRYPOINT NET runtime image) and corresponds with the. This tutorial will use the ASP.NET Core runtime image (which contains the. This file is a text file named Dockerfile that doesn't have an extension.Ĭreate a file named Dockerfile in the directory containing the. The Dockerfile file is used by the docker build command to create a container image. Use the ls command to get a directory listing and verify that the file was created. \bin\Release\net6.0\publish\ĭirectory: C:\Users\dapine\App\bin\Release\net6.0\publish Open the Program.cs file in a text editor.įrom the App folder, get a directory listing of the publish folder to verify that the file was created.
For this tutorial, you'll use an app that loops indefinitely. The default template creates an app that prints to the terminal and then immediately terminates. The application will run, and print Hello World! below the command: dotnet run
Use the dotnet run command to start the app. Change directories and navigate into the App folder, from your terminal session. The dotnet new command creates a new folder named App and generates a "Hello World" console application. Your folder tree will look like the following: ? docker-working In the working folder, run the following command to create a new project in a subdirectory named app: dotnet new console -o App -n DotNet.Docker Open your terminal, create a working folder if you haven't already, and enter it. NET app that the Docker container will run. In this tutorial, the name docker-working is used as the working folder. A temporary working folder for the Dockerfile and.NET installed, use the dotnet -info command to determine which SDK you're using.
If you're using ASP.NET Core, see the Learn how to containerize an ASP.NET Core application tutorial. This tutorial is not for ASP.NET Core apps.