[Posts] Docker series AspNetCore Runtime VS .NetCore Runtime VS .NET Core SDK (IV) Docker series AspNetCore Runtime VS .NetCore Runtime VS .NET Core SDK (IV)

Docker Series AspNetCore Runtime VS .NetCore Runtime VS .NET Core SDK (d)

 
https://www.cnblogs.com/CreateMyself/p/11391646.html

 

Foreword

Next we slowly entered the hall Docker's use in .NET Core, before beginning such questions, we need to figure out some concepts, or else see the official follows a series of mirrors, we'll look ignorant force, in the end I do not know which one to use.

Copy the code
Copy the code

AspNetCore Runtime  VS .NetCore Runtime VS .NET Core SDK 

In this section we explain the official provided a series of mirrors are the latest images, you need to read this article and understand that if you see a mirror other Bowen provided beginning with microsoft, then that is obsolete is no longer desirable. Here additional more to say, many times we have seen some information, and then did not personally practice to achieve results described in the article, in most cases may have been updated official cause, it is the best of all the main official documents . We will provide a mirror image of the official explained as follows:

Mirroring address

Mirroring name Mirror Description

mcr.microsoft.com/dotnet/core/runtime

 .NET Core Runtime Deploy .NET Core Console program
mcr.microsoft.com/dotnet/core/runtime-deps 

.NET Core Runtime Dependencies

Deploying applications self-contained

mcr.microsoft.com/dotnet/core/sdk 

.NET Core SDK Construction of .NET Core (or ASP.NET Core application)

mcr.microsoft.com/dotnet/core/aspnet 

ASP.NET Core Runtime Deploy ASP.NET Core Applications

Above for .NET Core Runtime Dependencies image package I did not do too much to understand, there is a detailed description of the named "SCD" on official documents, send address " https://docs.microsoft.com/en-gb/ DOTNET / Core / Deploying / index # Self-Contained-the Deployments-SCD ", do so many packages, seems like a very complicated, in fact, we only need to keep in mind the following two points:

For building .NET Core application, use the .NET Core SDK

For running .NET Core application, use the .NET Core Runtime

Such as the one we build, publish applications directly in local, so we just build a .NET Core Runtime Mirror, mirror if you need to publish in advance download .NET Core SDK mirror, then we run webapi illustrated by mirroring SDK to build the program, Runtime to run the program. It should be noted, the preview version 3.0 if downloaded directly here run the following command to create version 3.0, this time may be due to the lack of a corresponding package and restore failed, so here we will command (  DOTNET new new globaljson --sdk-Version 2.2.203 --force) fall back to 2.2 stable version, continue to go down.

Up to this point we have not as straightforward as a release, we will drag it directly in ubuntu, as follows:

Here for the contents of a supplement to say (personally have obsessive-compulsive disorder, mirroring the name of the one created for (hellowrold), this image by playing tag name wrong word, it should be helloworld, so here we rename mirroring label name. and master a command, ha ha. first, we view mirror, as follows

In Docker rename tag name mirror in two ways, one direct to rename tag by name, but by mirroring rename id, as follows:

docker tag hellowrold:latest helloworld:latest

或

docker tag 75a287b4f21c helloworld:latest

We as a way to rename any view mirror and then, as follows:

Because the container there is a reference to the old image, so the old will still exist rather than a new full coverage, so we then execute the following command to remove the old image:

docker rmi hellowrold

Deletes the alias / label by executing the above command, as 75a287b4f21c has a different name, it will not delete the actual image.

Back to the topic, then we begin to build webapi mirrored by Dockerfile, as follows:

Copy the code
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /app

COPY *.csproj ./
RUN dotnet restore

COPY . ./
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
WORKDIR /app

COPY --from=build /app/out .

ENTRYPOINT ["dotnet", "WebApi.dll"]
Copy the code

First we build the base image SDK to build applications, we specify the / app as the working directory we build. Then copy the files from the local file system to the mirror, we'll just copy csproj file and run the restore, and then copy the file and run the other remaining dotnet publish our application to build and publish. Run the file docker use different portions of the base image is an image used aspnetcore-runtime, it copies all the files in the build and definition of the application entry point. We found throughout the different stages of the construction of the mirroring process is interactive, because, as we get to build the first phase of the program mirror is an alias for the build, get to run the program in the second phase that is a mirror runtime, we refer to build.

From the above, we construct the image command and a known comparison, the command can be constructed  . -T tagname or Build Docker  Docker -t Tagname Build. These two methods to can be. Construction of Mirror Mirror is based on a layer and create a new image layer process, each new image layer corresponds to a unique identifier id, we can see a history mirrored built with the following command:

docker image history webapi:latest

Mirror "" none "" Description

When we're done building your image, we see the mirror list will see this time will be more of a mirror image of the label name to none, as follows:

What is the role of the mirror none generated as described above is it? We are not able to remove it?

Advantages: It is used to maintain the intermediate layer mirror, as described for each step of each Dockerfile, will create a new hash value as an intermediate layer to improve reusability by allowing each cache step, and reducing the amount of disk accelerate the construction of docker.

Cons: It vacant as a mirror, may cause disk space problems, but it is listed as part of docker image. (Docker hollow file system layer is not used, and is not referenced in any mirror, so we need a mechanism to allow Docker remove these empty mirror)

none mirroring only saved as a temporary container only, due to the Docker's architecture, even if the container is stopped, these floating image is still retained, so that we can be clean up, we can use  docker rmi $ (docker images -f " dangling = true "-q) to clean them, -f" dangling = true "-q show all vacant mirror, rmi will delete all the images, but if there is no vacant mirror execute this command, an error is returned, but we can use  docker images prune -a (only applies to more than 1.25 docker version).

Next is to create and launch container run the program, we configured on a port number in the code is 5000, and also by  docker run -p 5050: 5050 hellowrold specify the same port number to run the program, here we are not in the code configure the port, the default port number is 80, as follows:

docker run webapi:latest

Then if we visit http: // localhost / api / values, we will not see the connection, that is not what we expect JSON response.

This is why it? Let's look at the name docker to our generation container, docker container to a randomly generated name such as the following:

Next we fix by running the container terminal management command, we first vessel to stop, and then remove the following command:

docker container stop gracious_chaplygin
docker container rm gracious_chaplygin

We need to replace the container gracious_chaplygi name returned from the docker container ls, we use the following command to start the container again:

docker run --name webapi --env ASPNETCORE_ENVIRONMENT=Production -p 80:80 webapi:latest

We configured the above three parameters, - name is the name of the container is up and running, - env ​​environment variables allow us to pass the container to the running, -p allows us to map to the container port in our machine port on.

As container has started, we again use the ls command to view the name and port mapping we offer:

I guess probably because the above question container name randomly generated, and then specify the name of the vessel, the results of Hao Shi, but these findings again when we get the name of the vessel is still the name of the container randomly generated, so I think this is not a problem cause, and on the one we run container made in this section contrast, just specify the mapping port number, and this section does not specify the port number, default start port number is 80, the container also run up ah, finally found or did not specify the port number of reasons, because when I started container, also follows explicitly specify the port number like 80, so the next note here.

to sum up 

In this section we explain the issues the corresponding .NET Core image package installed in Docker, and an example to illustrate, but do we use on the basis of a directive on the use and add additional WORKDIR and RUN command, as well as to stop the container, remove, list view mirror, mirror rename, delete mirror, mirror build history to view instructions to use. Next, we will continue to be used flexibly by example to various commands, and then in the process also involves some can be optimized, and Docker in such volume, network more in-depth explanation.


In order to facilitate the moving end can see my share of Bowen, is now registered public personal number, scan the upper left of the two-dimensional code can welcome everyone's attention, the time will be the timely sharing of relevant technical Bowen. 

Thank spend the time to read this article, if you think this article you learned something under the code word is to reward bloggers might easily a reward about it, so that the landlord can drink a cup of coffee in this thanked the!
If you feel that you have read this article to help, please click the " recommend " button, your "recommended" will be my greatest writing power!
This article belongs to the author and blog Park total, source URL: http://www.cnblogs.com/CreateMyself)/ welcome you to reprint, but without the author's consent, then reprint articles must give the original author and the apparent position of the article page connection , otherwise the right to pursue legal responsibilities.
Stay hungry, stay foolish, A lifetime learner.

Foreword

Next we slowly entered the hall Docker's use in .NET Core, before beginning such questions, we need to figure out some concepts, or else see the official follows a series of mirrors, we'll look ignorant force, in the end I do not know which one to use.

Copy the code
Copy the code

AspNetCore Runtime  VS .NetCore Runtime VS .NET Core SDK 

In this section we explain the official provided a series of mirrors are the latest images, you need to read this article and understand that if you see a mirror other Bowen provided beginning with microsoft, then that is obsolete is no longer desirable. Here additional more to say, many times we have seen some information, and then did not personally practice to achieve results described in the article, in most cases may have been updated official cause, it is the best of all the main official documents . We will provide a mirror image of the official explained as follows:

Mirroring address

Mirroring name Mirror Description

mcr.microsoft.com/dotnet/core/runtime

 .NET Core Runtime Deploy .NET Core Console program
mcr.microsoft.com/dotnet/core/runtime-deps 

.NET Core Runtime Dependencies

Deploying applications self-contained

mcr.microsoft.com/dotnet/core/sdk 

.NET Core SDK Construction of .NET Core (or ASP.NET Core application)

mcr.microsoft.com/dotnet/core/aspnet 

ASP.NET Core Runtime Deploy ASP.NET Core Applications

Above for .NET Core Runtime Dependencies image package I did not do too much to understand, there is a detailed description of the named "SCD" on official documents, send address " https://docs.microsoft.com/en-gb/ DOTNET / Core / Deploying / index # Self-Contained-the Deployments-SCD ", do so many packages, seems like a very complicated, in fact, we only need to keep in mind the following two points:

For building .NET Core application, use the .NET Core SDK

For running .NET Core application, use the .NET Core Runtime

Such as the one we build, publish applications directly in local, so we just build a .NET Core Runtime Mirror, mirror if you need to publish in advance download .NET Core SDK mirror, then we run webapi illustrated by mirroring SDK to build the program, Runtime to run the program. It should be noted, the preview version 3.0 if downloaded directly here run the following command to create version 3.0, this time may be due to the lack of a corresponding package and restore failed, so here we will command (  DOTNET new new globaljson --sdk-Version 2.2.203 --force) fall back to 2.2 stable version, continue to go down.

Up to this point we have not as straightforward as a release, we will drag it directly in ubuntu, as follows:

Here for the contents of a supplement to say (personally have obsessive-compulsive disorder, mirroring the name of the one created for (hellowrold), this image by playing tag name wrong word, it should be helloworld, so here we rename mirroring label name. and master a command, ha ha. first, we view mirror, as follows

In Docker rename tag name mirror in two ways, one direct to rename tag by name, but by mirroring rename id, as follows:

docker tag hellowrold:latest helloworld:latest

或

docker tag 75a287b4f21c helloworld:latest

We as a way to rename any view mirror and then, as follows:

Because the container there is a reference to the old image, so the old will still exist rather than a new full coverage, so we then execute the following command to remove the old image:

docker rmi hellowrold

Deletes the alias / label by executing the above command, as 75a287b4f21c has a different name, it will not delete the actual image.

Back to the topic, then we begin to build webapi mirrored by Dockerfile, as follows:

Copy the code
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /app

COPY *.csproj ./
RUN dotnet restore

COPY . ./
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
WORKDIR /app

COPY --from=build /app/out .

ENTRYPOINT ["dotnet", "WebApi.dll"]
Copy the code

First we build the base image SDK to build applications, we specify the / app as the working directory we build. Then copy the files from the local file system to the mirror, we'll just copy csproj file and run the restore, and then copy the file and run the other remaining dotnet publish our application to build and publish. Run the file docker use different portions of the base image is an image used aspnetcore-runtime, it copies all the files in the build and definition of the application entry point. We found throughout the different stages of the construction of the mirroring process is interactive, because, as we get to build the first phase of the program mirror is an alias for the build, get to run the program in the second phase that is a mirror runtime, we refer to build.

From the above, we construct the image command and a known comparison, the command can be constructed  . -T tagname or Build Docker  Docker -t Tagname Build. These two methods to can be. Construction of Mirror Mirror is based on a layer and create a new image layer process, each new image layer corresponds to a unique identifier id, we can see a history mirrored built with the following command:

docker image history webapi:latest

Mirror "" none "" Description

When we're done building your image, we see the mirror list will see this time will be more of a mirror image of the label name to none, as follows:

What is the role of the mirror none generated as described above is it? We are not able to remove it?

Advantages: It is used to maintain the intermediate layer mirror, as described for each step of each Dockerfile, will create a new hash value as an intermediate layer to improve reusability by allowing each cache step, and reducing the amount of disk accelerate the construction of docker.

Cons: It vacant as a mirror, may cause disk space problems, but it is listed as part of docker image. (Docker hollow file system layer is not used, and is not referenced in any mirror, so we need a mechanism to allow Docker remove these empty mirror)

none mirroring only saved as a temporary container only, due to the Docker's architecture, even if the container is stopped, these floating image is still retained, so that we can be clean up, we can use  docker rmi $ (docker images -f " dangling = true "-q) to clean them, -f" dangling = true "-q show all vacant mirror, rmi will delete all the images, but if there is no vacant mirror execute this command, an error is returned, but we can use  docker images prune -a (only applies to more than 1.25 docker version).

Next is to create and launch container run the program, we configured on a port number in the code is 5000, and also by  docker run -p 5050: 5050 hellowrold specify the same port number to run the program, here we are not in the code configure the port, the default port number is 80, as follows:

docker run webapi:latest

Then if we visit http: // localhost / api / values, we will not see the connection, that is not what we expect JSON response.

This is why it? Let's look at the name docker to our generation container, docker container to a randomly generated name such as the following:

Next we fix by running the container terminal management command, we first vessel to stop, and then remove the following command:

docker container stop gracious_chaplygin
docker container rm gracious_chaplygin

We need to replace the container gracious_chaplygi name returned from the docker container ls, we use the following command to start the container again:

docker run --name webapi --env ASPNETCORE_ENVIRONMENT=Production -p 80:80 webapi:latest

We configured the above three parameters, - name is the name of the container is up and running, - env ​​environment variables allow us to pass the container to the running, -p allows us to map to the container port in our machine port on.

As container has started, we again use the ls command to view the name and port mapping we offer:

I guess probably because the above question container name randomly generated, and then specify the name of the vessel, the results of Hao Shi, but these findings again when we get the name of the vessel is still the name of the container randomly generated, so I think this is not a problem cause, and on the one we run container made in this section contrast, just specify the mapping port number, and this section does not specify the port number, default start port number is 80, the container also run up ah, finally found or did not specify the port number of reasons, because when I started container, also follows explicitly specify the port number like 80, so the next note here.

to sum up 

In this section we explain the issues the corresponding .NET Core image package installed in Docker, and an example to illustrate, but do we use on the basis of a directive on the use and add additional WORKDIR and RUN command, as well as to stop the container, remove, list view mirror, mirror rename, delete mirror, mirror build history to view instructions to use. Next, we will continue to be used flexibly by example to various commands, and then in the process also involves some can be optimized, and Docker in such volume, network more in-depth explanation.


In order to facilitate the moving end can see my share of Bowen, is now registered public personal number, scan the upper left of the two-dimensional code can welcome everyone's attention, the time will be the timely sharing of relevant technical Bowen. 

Thank spend the time to read this article, if you think this article you learned something under the code word is to reward bloggers might easily a reward about it, so that the landlord can drink a cup of coffee in this thanked the!
If you feel that you have read this article to help, please click the " recommend " button, your "recommended" will be my greatest writing power!
This article belongs to the author and blog Park total, source URL: http://www.cnblogs.com/CreateMyself)/ welcome you to reprint, but without the author's consent, then reprint articles must give the original author and the apparent position of the article page connection , otherwise the right to pursue legal responsibilities.

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/12529729.html