我是Docker新手-container?tabs = Windows“ rel =” nofollow noreferrer”> https://learn.microsoft.com/en-us/dotnet/core/core/docker/docker/build-container?tabs=windows
这是Docker文件 在上面的示例中,简单的Hello World应用程序的定义
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "DotNet.Docker.dll"]
是什么是 build-env
从此行复制-from = build-env/app/out。
?
我尝试了Google,但没有返回相关文章,也无法在官方文档中找到任何帮助。
在教程页面上说
复制命令告诉Docker在您的
计算机到容器中的文件夹。在此示例中,发布
文件夹被复制到容器中名为应用的文件夹。
我假设作者是指我们将/app/out 的内容复制到/app 文件夹,因为没有名为/Publish 的文件夹。因此,目标文件夹由上一行定义: Wordir /App < /code>。当我最初阅读复制-from = build-env/app/out。
我以为它从/build-env app/app/out /build-env >但似乎并非如此。
另外,副本的目的是什么。 ./行?
I'm new to docker and I'm following Microsoft's tutorial for building a .net core console app with docker at https://learn.microsoft.com/en-us/dotnet/core/docker/build-container?tabs=windows
This is the docker file definition for a simple Hello World app
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "DotNet.Docker.dll"]
In the above example, what is build-env
from this line COPY --from=build-env /app/out .
?
I tried google, but no relevant articles are returned and can't find any help in the official docs either.
In the tutorial page it says
The COPY command tells Docker to copy the specified folder on your
computer to a folder in the container. In this example, the publish
folder is copied to a folder named app in the container.
I assume the author means we copy the contents of /app/out to the /app folder, as there is no folder named /publish. So the destination folder is defined by the previous line: WORDIR /app
. When I initially read COPY --from=build-env /app/out .
I assumed it copies from /build-env to app/out but this doesn't seem to be the case.
Also, what is the purpose of the COPY . ./
line?
发布评论
评论(2)
build-env
此上下文只是mcr.microsoft.com/dotnet/sdk:6.0
图像的别名。为图像创建别名的语法如下:
[image_name]为[别扬]
现在您可以使用dockerfile中的别名而不是冗长的图像名称。
复制-from = build-env /app /out。< /code> copies /app /out从基于build-env的容器到新图像上的workdir /app将从此Dockerfile构建的新图像上。
复制。 ./将在此Dockerfile位于该目录的目录中的目录中的内容>
workdir/app
将在新图像上从该dockerfile构建。build-env
this context is just an alias tomcr.microsoft.com/dotnet/sdk:6.0
image.The syntax to create an alias for an image is as follows:
[image_name] AS [Alias]
Now you can use the Alias instead of the lengthy image name in your Dockerfile.
COPY --from=build-env /app/out .
copies /app/out from build-env based container to The WORKDIR /app on the new image that will be built from this dockerfile.COPY . ./
will copy the contents of the directory where this dockerfile is located to theWORKDIR /app
on the new image that will be built from this dockerfile.build-env在Dockerfile的第一行中定义:mcr.microsoft.com/dotnet/sdk:6.0
副本。 ./意味着将所有文件从SRC位置(当前)复制到目标(./)。您可以在
build-env is defined in the first line of the dockerfile: mcr.microsoft.com/dotnet/sdk:6.0
The copy . ./ means to copy all files from src location (current) to destination (./) . You can get more details on dockerfile in https://docs.docker.com/engine/reference/builder/