• <i id='3KZZf'><tr id='3KZZf'><dt id='3KZZf'><q id='3KZZf'><span id='3KZZf'><b id='3KZZf'><form id='3KZZf'><ins id='3KZZf'></ins><ul id='3KZZf'></ul><sub id='3KZZf'></sub></form><legend id='3KZZf'></legend><bdo id='3KZZf'><pre id='3KZZf'><center id='3KZZf'></center></pre></bdo></b><th id='3KZZf'></th></span></q></dt></tr></i><div id='3KZZf'><tfoot id='3KZZf'></tfoot><dl id='3KZZf'><fieldset id='3KZZf'></fieldset></dl></div>

    <small id='3KZZf'></small><noframes id='3KZZf'>

    <legend id='3KZZf'><style id='3KZZf'><dir id='3KZZf'><q id='3KZZf'></q></dir></style></legend>
      <bdo id='3KZZf'></bdo><ul id='3KZZf'></ul>
      <tfoot id='3KZZf'></tfoot>

      1. 复制 ..用于 ASP.NET 的 Dockerfile 中的命令

        时间:2023-09-17
            <tbody id='egLha'></tbody>

          <small id='egLha'></small><noframes id='egLha'>

            • <bdo id='egLha'></bdo><ul id='egLha'></ul>

            • <tfoot id='egLha'></tfoot>

                <i id='egLha'><tr id='egLha'><dt id='egLha'><q id='egLha'><span id='egLha'><b id='egLha'><form id='egLha'><ins id='egLha'></ins><ul id='egLha'></ul><sub id='egLha'></sub></form><legend id='egLha'></legend><bdo id='egLha'><pre id='egLha'><center id='egLha'></center></pre></bdo></b><th id='egLha'></th></span></q></dt></tr></i><div id='egLha'><tfoot id='egLha'></tfoot><dl id='egLha'><fieldset id='egLha'></fieldset></dl></div>

                  <legend id='egLha'><style id='egLha'><dir id='egLha'><q id='egLha'></q></dir></style></legend>
                1. 本文介绍了复制 ..用于 ASP.NET 的 Dockerfile 中的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Docker 的 Visual Studio 工具为包含 COPY 的 ASP.NET 项目创建 Dockerfile.. 命令如下:

                  The Visual Studio tooling for Docker creates a Dockerfile for ASP.NET projects containing a COPY . . command as below:

                  WORKDIR /src
                  COPY *.sln ./
                  ...
                  COPY . .
                  

                  根据我的阅读,<src> 参数与上下文相关,因此不受 WORKDIR/src 命令的影响.然而,<dest> 是相对于 WORKDIR 的,因此将指向 /src.

                  From what I've read, the <src> parameter is relative to the context, so isn't affected by the WORKDIR /src command. The <dest> however is relative to the WORKDIR so will be pointing at /src.

                  此命令是否只是从根目录中提取剩余文件进行打包(docker-compose.yml、.dockerignore 等)?如果是这样,那为什么要在 RUN dotnet build... 命令之前完成?

                  Is this command just bringing over the remaining files from the root for packaging (docker-compose.yml, .dockerignore, etc.)? If so, then why is this done ahead of the RUN dotnet build... command?

                  完整的 Dockerfile 如下:

                  Full Dockerfile below:

                  FROM microsoft/aspnetcore:2.0 AS base
                  WORKDIR /app
                  EXPOSE 80
                  
                  FROM microsoft/aspnetcore-build:2.0 AS build
                  WORKDIR /src
                  COPY *.sln ./
                  COPY MyProject/MyProject.csproj MyProject/
                  RUN dotnet restore
                  COPY . . # The line mentioned above
                  WORKDIR /src/MyProject
                  RUN dotnet build -c Release -o /app
                  
                  FROM build AS publish
                  RUN dotnet publish -c Release -o /app
                  
                  FROM base AS final
                  WORKDIR /app
                  COPY --from=publish /app .
                  ENTRYPOINT ["dotnet", "MyProject.dll"]
                  

                  推荐答案

                  COPY .. 将整个项目以递归方式复制到构建容器中.

                  The COPY . . copies the entire project, recursively into the container for the build.

                  前 2 个 COPY 命令与 dotnet restore 以及完整的 COPYdotnet build<分开的原因/code> 是一个 Docker 缓存技巧,用于加快容器映像的构建.这样做是为了不需要在每次更改代码时都安装项目依赖项.

                  The reason for the separation of the first 2 COPY commands with dotnet restore and then the complete COPY with dotnet build is a Docker caching trick to speed up container image builds. It is done this way so the project dependencies don't need to be installed every time a code change is made.

                  Docker 镜像是分层构建的.Docker 将构成每个新层的内容和指令与以前的构建进行比较.如果它们与现有层的 SHA256 校验和匹配,则可以跳过该层的构建步骤.

                  Docker images are built in layers. Docker compares the contents and instructions that would make up the each new layer to previous builds. If they match the SHA256 checksum for the existing layer, the build step for that layer can be skipped.

                  代码的变化比依赖项要多得多,现在依赖项通常是从一个慢(ish)网络中获取的.如果在依赖项安装完成后复制代码,则不会因其他更改而破坏缓存的依赖项层.

                  Code changes a lot more than dependencies, and dependencies are usually fetched from a slow(ish) network now. If you copy the code after the dependency installs are completed then you don't bust the cached dependency layer for every other change.

                  这是一个跨多种语言的通用主题,带有依赖项管理器.Go、Python、Node.js 等.Node.js 等效项在其余应用程序内容之前执行 package.jsonpackage-lock.json:

                  This is a common theme across many languages with a dependency manager. Go, Python, Node.js etc. The Node.js equivalent does the package.json and package-lock.json before the rest of the application contents:

                  WORKDIR /app
                  COPY package.json package-lock.json /app/
                  RUN npm install
                  COPY . /app/
                  CMD ["node", "app/index.js"]
                  

                  这篇关于复制 ..用于 ASP.NET 的 Dockerfile 中的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                    1. <legend id='ISa6F'><style id='ISa6F'><dir id='ISa6F'><q id='ISa6F'></q></dir></style></legend>
                      <tfoot id='ISa6F'></tfoot>
                      <i id='ISa6F'><tr id='ISa6F'><dt id='ISa6F'><q id='ISa6F'><span id='ISa6F'><b id='ISa6F'><form id='ISa6F'><ins id='ISa6F'></ins><ul id='ISa6F'></ul><sub id='ISa6F'></sub></form><legend id='ISa6F'></legend><bdo id='ISa6F'><pre id='ISa6F'><center id='ISa6F'></center></pre></bdo></b><th id='ISa6F'></th></span></q></dt></tr></i><div id='ISa6F'><tfoot id='ISa6F'></tfoot><dl id='ISa6F'><fieldset id='ISa6F'></fieldset></dl></div>

                        <bdo id='ISa6F'></bdo><ul id='ISa6F'></ul>

                            <tbody id='ISa6F'></tbody>
                        1. <small id='ISa6F'></small><noframes id='ISa6F'>