Yur*_*kyy 4 docker dockerfile docker-for-windows docker-desktop
我写的Dockerfile是基于windowsnanoserver。我需要添加到这个图像 git。为了实现它,我做了以下事情:
RUN Invoke-WebRequest 'https://github.com/git-for-windows/git/releases/download/v2.12.2.windows.2/Git-2.12.2.2-64-bit.exe'
RUN Invoke-Expression "c:\Git-2.12.2.2-64-bit.exe"
Run Code Online (Sandbox Code Playgroud)
但是当我通过 docker build 执行此行时,我收到以下错误消息:
Invoke-Expression :术语“c:\Git-2.12.2.2-64-bit.exe”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。
我意识到此错误消息表明由于 Windows docker 映像的控制台性质,我将无法执行 GUI 安装程序。不幸的是 git 没有控制台安装程序。Chocolatey在windowsservercore图像下工作正常,但在windowsnanoserver下不起作用。为了为windowsnanoserver安装 git,我有想法重复Dockerfile来自巧克力 git 安装程序的命令,这对我来说很好,但我仍然想知道有没有更简单的方法可以在windowsnanoserver上安装 git ?
我已经通过使用 MinGit 并将有关 mingit 的信息放入环境/路径变量中解决了 GUI 问题。我使用了以下方法:
RUN Invoke-WebRequest 'https://github.com/git-for-windows/git/releases/download/v2.12.2.windows.2/MinGit-2.12.2.2-64-bit.zip' -OutFile MinGit.zip
RUN Expand-Archive c:\MinGit.zip -DestinationPath c:\MinGit; \
$env:PATH = $env:PATH + ';C:\MinGit\cmd\;C:\MinGit\cmd'; \
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\' -Name Path -Value $env:PATH
Run Code Online (Sandbox Code Playgroud)
你是对的,Windows 和 Linux 容器通常都专注于运行无头应用程序(即没有 GUI)。
听起来你想基于具有 git 的 nanoserver 镜像创建一个容器镜像?
巧克力是个好主意。
如果您向我提供您目标的更广泛背景,我可以为您提供进一步帮助。
干杯:)
根据此图片,使用 Chocolatey 安装对我有用:ehong
我将这些行添加到我的 Dockerfile 中:
ENV ChocolateyUseWindowsCompression false
RUN powershell Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
RUN powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
RUN choco install git.install -y --no-progress
Run Code Online (Sandbox Code Playgroud)
例如,要克隆具有子模块依赖项的更复杂的存储库,请包含ehonggit clone --recursive -b v1.42.0 https://github.com/grpc/grpc.git Dockerfile的其余部分:
# Install NuGet provider
RUN powershell -Command "Install-PackageProvider -Name NuGet -Force -Scope AllUsers -RequiredVersion 2.8.5.201 -ErrorAction Stop"
# Set the PSGallery as a trusted repository
RUN powershell -Command "Set-PSRepository -Name PSGallery -InstallationPolicy Trusted"
#Install posh-git
RUN powershell Install-Module -Name 'posh-git'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8693 次 |
| 最近记录: |