首页 > 解决方案 > Docker 返回退出代码 3221225781 安装 vc_redist.x64.exe

问题描述

我已经看到很多关于退出代码“3221225781”的问题,以响应 docker RUN,但我仍然无法找到答案。考虑这个 dockerfile:

FROM mcr.microsoft.com/dotnet/core/runtime:3.1
WORKDIR /app
ADD https://aka.ms/vs/16/release/vc_redist.x64.exe vc_redist.x64.exe
RUN VC_redist.x64.exe /install /quiet /norestart /log vc_redist.log

运行它时,我得到以下输出:

C:\test>docker image build -t exitcodetest:1.0 .
Sending build context to Docker daemon  113.2MB
Step 1/4 : FROM mcr.microsoft.com/dotnet/core/runtime:3.1
 ---> 3be5e0b7f3a5
Step 2/4 : WORKDIR /app
 ---> Using cache
 ---> 4508bead23e2
Step 3/4 : ADD https://aka.ms/vs/16/release/vc_redist.x64.exe vc_redist.x64.exe
Downloading [==================================================>]  15.06MB/15.06MB

 ---> 37322d63b677
Step 4/4 : RUN VC_redist.x64.exe /install /quiet /norestart /log vc_redist.log
 ---> Running in c57b67befa33
The command 'cmd /S /C VC_redist.x64.exe /install /quiet /norestart /log vc_redist.log' returned a non-zero code: 3221225781

为什么我会得到这个退出代码?这是什么意思?我还确认没有写入 vc_redist.log。

有人知道我能做些什么来让它工作吗?

我应该补充一点,当我在本地机器上运行该命令时它会起作用,并返回零 %ERRORLEVEL%。

谢谢!

标签: dockerdockerfile

解决方案


@ProfNimrod 我需要使用具有 Azure 可以使用的操作系统的图像,而不仅仅是一个带有 .NET 的层。所以我从这张图片开始,基本上复制了微软安装 .NET 的方式。我需要这样做,因为我的应用程序还在操作系统上安装了一些自定义驱动程序。可能有更好的方法,但我还没有看到。

# escape=`

# Use an Azure-supported image.
FROM mcr.microsoft.com/windows:1809-amd64

# Use PowerShell for the command shell because we will use it to install the .NET runtime
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]


# =================================================================
# Install .NET Core Runtime
# =================================================================

# Retrieve and install the .NET Core Runtime
RUN $dotnet_archive_file = 'C:\Windows\Temp\dotnet-runtime-3.1.2-win-x64.zip'; `
    $dotnet_archive_file_sha512 = '2986d9f04640115cfa1ec478ac20d8e5c0f3b57f1d4e379300dfbafe8d20ec775ea1987045d611a1b2d786de7e1981c57ef52824a9d8dda64e1570379187b23f'; `
    $dotnet_archive_url = 'https://dotnetcli.azureedge.net/dotnet/Runtime/3.1.2/dotnet-runtime-3.1.2-win-x64.zip'; `
    $dotnet_install_directory = 'C:\Program Files\dotnet'; `
    Invoke-WebRequest -OutFile $dotnet_archive_file $dotnet_archive_url; `
    if ((Get-FileHash $dotnet_archive_file -Algorithm sha512).Hash -ne $dotnet_archive_file_sha512) { `
        Write-Host \"CHECKSUM VERIFICATION FAILED: $dotnet_archive_url\"; `
        exit 1; `
    }; `
    Expand-Archive $dotnet_archive_file -DestinationPath $dotnet_install_directory; `
    Remove-Item -Force $dotnet_archive_file

# These common .NET-specific environment variables should be specified
ENV `
    # Configure web servers to bind to port 80 when present
    ASPNETCORE_URLS=http://+:80 `
    # Enable detection of running in a container
    DOTNET_RUNNING_IN_CONTAINER=true

# Update the global %PATH% to complete the .NET installation
# In order to set system PATH, ContainerAdministrator must be used
USER ContainerAdministrator
RUN $oldPath = [System.Environment]::GetEnvironmentVariable('path', [System.EnvironmentVariableTarget]::Machine); `
    $dotnet_install_directory = 'C:\Program Files\dotnet'; `
    $setx_process = Start-Process -FilePath 'setx.exe' -ArgumentList \"/M PATH \"\"$oldPath;$dotnet_install_directory\"\"\" -NoNewWindow -Wait -PassThru; `
    if ($setx_process.ExitCode -ne 0) { `
        Write-Host \"PROCESS FAILED: setx.exe (Exit Code: $($setx_process.ExitCode))\"; `
        exit 1; `
    }
USER ContainerUser

推荐阅读