Im trying to install Chocolatey into a docker windows container, on a Windows 10 Machine using a Windows Container and not linux containers. Im running the docker build command in the PowerShell console and every time it get to trying to install Chocolatey using the line: Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
It comes back with:
Exception calling "DownloadString" with "1" argument(s): "The remote name could not be resolved: 'chocolatey.org'"
At line:1 char:166
+ ... -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('ht ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
It cant seem to resolve the chocolatey.org part and I'm specifying the network card in my build command:
docker build --network 21fb9a254e4b --progress=plain --tag jcontent/dockerwinbaseimage .
I have also specified the DNS settings in the Daemon file to look at 8.8.8.8 this is in testing it was not working before this....
I have attached my Build Script. Any Help would be appreciated.
# escape=`
FROM microsoft/dotnet-framework:4.7.2-sdk-windowsservercore-ltsc2016
FROM microsoft/windowsservercore:10.0.14393.1358
RUN #powershell [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
ENV chocolateyUseWindowsCompression=false
RUN #powershell Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RUN choco config set cachelocation C:\chococache
RUN choco feature enable --name allowGlobalConfirmation
RUN choco install git;
RUN choco install nodejs;
RUN choco install curl;
RUN choco install docker;
RUN choco install terraform;
# choco install visualstudio2015community --confirm --timeout 216000 \
RUN choco install dotnet4.6.1 --confirm --limit-output;
RUN choco install visualstudio2017enterprise --package-parameters "--passive --locale en-US --includeOptional" --confirm --limit-output --timeout 216000;
RUN choco install visualstudio2017-workload-azure --confirm --limit-output --timeout 21600 --package-parameters "--includeOptional";
RUN choco install visualstudio2017-workload-netcoretools --confirm --limit-output --timeout 21600 --package-parameters "--includeOptional";
RUN choco install visualstudio2017-workload-netweb --confirm --limit-output --timeout 21600 --package-parameters "--includeOptional";
# Destroy Choclotatey cache
RUN rmdir /S /Q C:\chococache
# common node tools
RUN npm install gulp -g && npm install grunt -g && npm install -g less && npm install phantomjs-prebuilt -g;
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# Install .NET Core
ENV DOTNET_VERSION 3.1.7
ENV DOTNET_DOWNLOAD_URL https://dotnetcli.blob.core.windows.net/dotnet/release/1.1.0/Binaries/$DOTNET_VERSION/dotnet-win-x64.$DOTNET_VERSION.zip
RUN Invoke-WebRequest $Env:DOTNET_DOWNLOAD_URL -OutFile dotnet.zip; \
RUN Expand-Archive dotnet.zip -DestinationPath $Env:ProgramFiles\dotnet -Force; \
RUN Remove-Item -Force dotnet.zip
# Install .NET Core
ENV DOTNET_VERSION 3.1.7
ENV DOTNET_DOWNLOAD_URL https://dotnetcli.blob.core.windows.net/dotnet/preview/Binaries/$DOTNET_VERSION/dotnet-win-x64.$DOTNET_VERSION.zip
RUN Invoke-WebRequest $Env:DOTNET_DOWNLOAD_URL -OutFile dotnet.zip; \
RUN Expand-Archive dotnet.zip -DestinationPath $Env:ProgramFiles\dotnet -Force; \
RUN Remove-Item -Force dotnet.zip
# Install .NET Core SDK
ENV DOTNET_VERSION 3.1.7
ENV DOTNET_SDK_DOWNLOAD_URL https://dotnetcli.blob.core.windows.net/dotnet/Sdk/$DOTNET_SDK_VERSION/dotnet-dev-win-x64.$DOTNET_SDK_VERSION.zip
RUN Invoke-WebRequest $Env:DOTNET_SDK_DOWNLOAD_URL -OutFile dotnet.zip; \
RUN Expand-Archive dotnet.zip -DestinationPath $Env:ProgramFiles\dotnet -Force; \
RUN Remove-Item -Force dotnet.zip
SHELL ["cmd", "/S", "/C"]
RUN setx /M PATH "%PATH%;%ProgramFiles%\dotnet"
# Trigger the population of the local package cache
ENV NUGET_XMLDOC_MODE skip
RUN mkdir C:\warmup \
RUN cd C:\warmup \
RUN dotnet new \
RUN cd .. \
RUN rmdir /S /Q C:\warmup
#Change Working Directory to Install DevOps Tools
WORKDIR /azp
#Install DevOps Agents
COPY start.ps1 .
#Configure DevOps Agent
CMD powershell .\start.ps1
I managed to fix this frustrating problem today, here is what I did for when the next person has this issue, as Docker is not going to fix it any time soon.
What I did, is in the desktop app on Windows / Mac you can edit the Daemon file. Under Settings in the Docker App under Docker Engine, I added the line at the bottom of the file just above the last curly brace. "dns": [ "Your DNS Address Here", "8.8.8.8" ]
This then allows the Docker Containers all that you now build to use your host's DNS server. Technically if you can access: https://chocolatey.org/install.ps1 then you should be able to access the choco repository.
I have also built the image in https://github.com/jasric89/vsts-agent-docker/tree/master/windows/servercore/10.0.14393 and labeled it in the repo:
microsoft/windowsservercore:10.0.14393.1358
I then set: RUN choco feature enable --name allowGlobalConfirmation before my first Choco Install command, this enables choco to install all the files and not error.
With all that set my Docker File Ran and built the image. Well in my Test Env now testing in my prod env. :)
Links that helped me:
https://github.com/moby/moby/issues/24928
https://github.com/jasric89/vsts-agent-docker/blob/master/windows/servercore/10.0.14393/standard/VS2017/Dockerfile
https://docs.chocolatey.org/en-us/troubleshooting
https://github.com/moby/moby/issues/25537
UPDATE:
I ran into this problem again on a fresh build and after following my own instructions it didn't quite work.
I realised after a couple more hours of testing that Docker on Windows uses the Hyper-V Network setup.
Within my Hyper V Switch Manager, I did not have a network, with Internet Access. Also when I tried to change the default switch it would not let me. Therefore I had to create a new network within the Hyper-V Network.
I then had to edit the docker Daemon file, in the Docker Settings to tell it to use the right network, and also I put in the DNS settings I specified before in my Anwser.
Here is my full docker daemon file:
{
"registry-mirrors": [],
"insecure-registries": [],
"bridge": "Internet",
"dns": [
"YOUR Local DNS Address Here",
"8.8.8.8"
],
"debug": false,
"experimental": false
}
Thanks to #jason for a great answer which actually helped me a lot to resolve this. In the end, a combination of the Chocolatey install docs and a few other online resources, and I got this to work:
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
WORKDIR /app
RUN Set-ExecutionPolicy Bypass -Scope Process -Force; \
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; \
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'));
RUN choco install dotnetcore-runtime --version 2.2.7 -y;
RUN choco install aspnetcore-runtimepackagestore --version 2.2.7 -y;
Related
I'm trying to install VirtualBox from an electron app to the host machine.
Currently I do the following:
(virtualbox installer is packaged in the electron app)
await util.sudoExec(`
copy ${app.getAppPath()}\\..\\resources\\installers\\VirtualBox-6.1.8-137981-Win.exe ${temp}\\pkg.exe &
${temp}\\pkg.exe /extract --silent &
msiexec /i ${temp}\\VirtualBox\\VirtualBox-6.1.8-r137981.msi /quiet /norestart ALLUSERS=2 VBOX_INSTALLDESKTOPSHORTCUT=0 VBOX_INSTALLQUICKLAUCHSHORTCUT=0
`)
The above code is working 70%. In some cases I got an error message ie.:
'C:\Users\Username\AppData\Local\Temp\pkg.exe' is not recognized as an internal or external command,
operable program or batch file.
I'm not sure this is the best way to install VB.
You could try to use Chocolatey:
This will install it:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
And this command will install Virtualbox:
choco install virtualbox -y
This would also allow you to easily update the software whenever you need to. It's an option so you don't need to maintain package installers for each version of VB.
There is an answer , I think it could help you
'' is not recognized as an internal or external command, operable program or batch file
see the answer of Gerhard on this question
Yo fellow stackoverflow-ers!
I've recently hit a snag when trying to create a windows container that runs IIS. Currently, my dockerfile looks like the following
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.7.2-windowsservercore-ltsc2016
# Install Powershell
ADD https://github.com/PowerShell/PowerShell/releases/download/v7.0.0/PowerShell-7.0.0-win-x64.zip c:/powershell.zip
RUN powershell.exe -Command Expand-Archive c:/powershell.zip c:/PS7 ; Remove-Item c:/powershell.zip
RUN C:/PS7/pwsh.EXE -Command C:/PS7/Install-PowerShellRemoting.ps1
# Update shell to powershell (PS7)
SHELL ["C:/PS7/pwsh.EXE", "-command"]
# Install chocolatey
RUN Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# Install application dependencies via chocolatey
RUN choco install -y vcredist140
RUN choco install -y nuget.commandline
# Enable required IIS features
RUN Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebSockets;
RUN Enable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationInit;
RUN Enable-WindowsOptionalFeature -Online -FeatureName IIS-BasicAuthentication;
RUN Enable-WindowsOptionalFeature -Online -FeatureName IIS-WindowsAuthentication;
RUN Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpCompressionDynamic;
# Install IISAdministration to manage IIS configuration
RUN Install-Module -Name IISAdministration -Force -MinimumVersion "1.1.0.0";
# Remove default web site
RUN Remove-IISSite -Name 'Default Web Site'
This results in the following error when the last command is called
Remove-IISSite: The term 'Remove-IISSite' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Note: I'm using PS7, as the current Powershell version that comes with the above container doesn't allow me to install IISAdministration (which is slightly annoying, but hey-ho! Probably something I'm doing wrong).
Any help and/or advice on the current situation would be greatly appreciated!
As per your comment, I have had issues specifically on Server Core 2016 too with PowerShell Modules, so can sympathise. The IISAdministration module has not been ported to .NET Core. You would have to use the current Desktop version of PowerShell i.e. 5.1.
The simplest solution is to use Import-Module IISAdministration -UseWindowsPowerShell instead of Install-Module -Name IISAdministration.
That's how PowerShell 7 loads old modules in the compatible way (a remote session to 5.1),
Reference
I am trying to use chocolatey to install packages into a windows container. I actually just wanted to change one of the packages, rebuild and push and now, suddenly, it doesn't work. When I test it on the host (run the same command as the container) it works just fine. It has some kind of an issue with that container installation since last build. I can only suspect the base image changed. But, maybe not
On the host:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Getting latest version of the Chocolatey package for download.
Getting Chocolatey from https://chocolatey.org/api/v2/package/chocolatey/0.10.15.
Downloading 7-Zip commandline tool prior to extraction.
Extracting C:\Users\ADMINI~1\AppData\Local\Temp\chocolatey\chocInstall\chocolatey.zip to C:\Users\ADMINI~1\AppData\Local\Temp\chocolatey\chocInstall...
Installing chocolatey on this machine
Creating ChocolateyInstall as an environment variable (targeting 'Machine')
Setting ChocolateyInstall to 'C:\ProgramData\chocolatey'
WARNING: It's very likely you will need to close and reopen your shell
before you can use choco.
Restricting write permissions to Administrators
We are setting up the Chocolatey package repository.
The packages themselves go to 'C:\ProgramData\chocolatey\lib'
(i.e. C:\ProgramData\chocolatey\lib\yourPackageName).
A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin'
and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName'.
Creating Chocolatey folders if they do not already exist.
WARNING: You can safely ignore errors related to missing log files when
upgrading from a version of Chocolatey less than 0.9.9.
'Batch file could not be found' is also safe to ignore.
'The system cannot find the file specified' - also safe.
chocolatey.nupkg file not installed in lib.
Attempting to locate it from bootstrapper.
PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Adding...
WARNING: Not setting tab completion: Profile file does not exist at
'C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'.
Chocolatey (choco.exe) is now ready.
You can call choco from anywhere, command line or powershell by typing choco.
Run choco /? for a list of functions.
You may need to shut down and restart powershell and/or consoles
first prior to using choco.
Ensuring chocolatey commands are on the path
Ensuring chocolatey.nupkg is in the lib folder
same host, but this time, in a Dockerfile
PS C:\Users\Administrator\example> cat Dockerfile
# escape=`
ARG SDK_VERSION=4.8
# Use the latest Windows Server Core image with .NET Framework 4.8.
FROM mcr.microsoft.com/dotnet/framework/sdk:${SDK_VERSION}
# Disable Healthcheck
HEALTHCHECK NONE
RUN Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RUN choco install adoptopenjdk8openj9jre -y
RUN choco install nuget.commandline -y
RUN choco install yarn -y
RUN choco install gitversion.portable -y
RUN choco install sonarscanner-msbuild-net46 -y
CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]
PS C:\Users\Administrator\example> docker build -t example .
Sending build context to Docker daemon 4.096kB
Step 1/10 : ARG SDK_VERSION=4.8
Step 2/10 : FROM mcr.microsoft.com/dotnet/framework/sdk:${SDK_VERSION}
4.8: Pulling from dotnet/framework/sdk
65014b3c3121: Already exists
b5405b758079: Pull complete
ac56c610af03: Pull complete
d8d61c2ababf: Pull complete
0ed57babb001: Pull complete
c8a0f45b3421: Pull complete
75cb34f91825: Pull complete
1949a0bb0ffb: Pull complete
316fdf3fc0fa: Pull complete
42b0925a3e5c: Pull complete
c5e384761600: Pull complete
f65f633b9854: Pull complete
bd885be04626: Pull complete
179844769b6b: Pull complete
c037183d4738: Pull complete
Digest: sha256:0008d5d893924c10ec01b1619a009c57116f9a943fe43ca772af544c75c9a83a
Status: Downloaded newer image for mcr.microsoft.com/dotnet/framework/sdk:4.8
---> 99ad7e1e8763
Step 3/10 : HEALTHCHECK NONE
---> Running in f679ce4e5789
Removing intermediate container f679ce4e5789
---> a08984a9afe8
Step 4/10 : RUN Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
---> Running in 656ed514a137
Getting latest version of the Chocolatey package for download.
Getting Chocolatey from https://chocolatey.org/api/v2/package/chocolatey/0.10.15.
Downloading 7-Zip commandline tool prior to extraction.
Extracting C:\Users\ContainerAdministrator\AppData\Local\Temp\chocolatey\chocInstall\chocolatey.zip to C:\Users\ContainerAdministrator\AppData\Local\Temp\chocolatey\chocInstall...
Unable to unzip package using 7zip. Perhaps try setting
$env:chocolateyUseWindowsCompression = 'true' and call install again. Error:
7-Zip signalled an unknown error (code -1073741511)
At line:220 char:15
+ ... default { throw "$errorMessage 7-Zip signalled an unknown error (co ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (Unable to unzip...de -1073741
511):String) [], RuntimeException
+ FullyQualifiedErrorId : Unable to unzip package using 7zip. Perhaps try
setting $env:chocolateyUseWindowsCompression = 'true' and call install aga
in. Error: 7-Zip signalled an unknown error (code -1073741511)
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))' returned a non-zero code: 1
PS C:\Users\Administrator\example>
There have been a few issues from TLS changes to changes to the microsoft base images that have caused me some problems with 7zip and choco over the last 3 weeks. I've got my base images working now by adding the following:
RUN $text = '[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls13 -bor [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Ssl3 -bor [Net.SecurityProtocolType]::Tls'; \
$text | Set-Content 'C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1';
RUN powershell -Command Set-ExecutionPolicy Bypass -Scope Process -Force; \
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')); \
powershell -Command refreshenv; \
cinst -y --allow-empty-checksums 7zip.install make nuget.commandline --no-progress;
However I am still experiencing some issue in other images with the reported error: "7-Zip signalled an unknown error (code -1073741511)", however no doubt they boil down to the same thing. Again, if I exec in to the running container, I am able to manually run choco and install 7zip and even access the "7z" commands. I tried committing the container once I made the changes, but still got this issue.
I installed docker on a Windows 10 machine via chocolatey
choco install docker-desktop
Then I have built this image
FROM mcr.microsoft.com/windows/servercore:ltsc2016
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
RUN Invoke-WebRequest -UseBasicParsing https://chocolatey.org/install.ps1 | Invoke-Expression
And it runs reasonably fast
Then I try to run this one
FROM chocolatey
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
RUN cinst -y netfx-4.7.2-devpack
After downloading the .net installer the process fails with timeout.
The last thing in the log is Installing dotnetfx...
No idea why and how to debug.
Anyone has the same issue? Where do I start debugging this issue?
I dont have a definitive answer for this but my current workaround is to use the sdk base image from microsoft from https://hub.docker.com/_/microsoft-dotnet-framework-sdk/
I setup a windows docker image and started it on my Windows 10 machine.
In the running docker image registered the gitlab runner at my gitlab server.
The problem is that the gitlab server sees the ip address of the host Windows machine and as a result things it is online.
Is there anyway to run a build runner in an interactive docker image?
Here is my dockerfile
# escape=`
FROM microsoft/windowsservercore
RUN #"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
# wait for vs_installer.exe, vs_installerservice.exe
# or vs_installershell.exe because choco doesn't
RUN powershell -NoProfile -InputFormat None -Command `
choco install git 7zip -y; `
choco install visualcpp-build-tools `
-y; `
Write-Host 'Waiting for Visual C++ Build Tools to finish'; `
Wait-Process -Name vs_installer
#WORKDIR C:\build
#CMD powershell -ExecutionPolicy Bypass -Command .\release.ps1
COPY entrypoint.bat entrypoint.bat
# Install Chocolatey
#RUN powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET #"PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
# Register the GitLab Runner
COPY gitlab-runner-windows-amd64.exe /gitlab/gitlab-runner.exe
RUN /gitlab/gitlab-runner.exe install
SHELL ["cmd.exe", "/s", "/c", "C:\\entrypoint.bat"]
WORKDIR /code
ENTRYPOINT ["C:\\entrypoint.bat"]
CMD ["cmd"]
EXPOSE 443
and my entrypoint.bat file
#echo off
pushd C:
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat"
REM call "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat"
popd
%*
Here is how I build it
docker build -t windows .
Here is how I run it
docker run -it windows cmd
Here is how I register the gitlab runner
C:\gitlab>gitlab-runner register --non-interactive --name "Windows docker builder" --url "https://gitlabserver/" --registration-token TOKEN --tag-list windows --executor shell
Registering runner... succeeded runner=XXX
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
On the GitLab Server I can see it is register but to it shows the ip address of the Windows 10 host machine not the ip address inside of docker.