I am running on Windows 2019 server.
I am getting an error whenever I invoke powershell from a dockerfile on docker build
Error is..
---> Running in 6efa29aa8a4a
The command 'powershell -Command DIR' returned a non-zero code: 3221226505
Dockerfile..
# escape=` (backtick)
FROM mcr.microsoft.com/windows/servercore:ltsc2019
RUN DIR
RUN ["powershell", "-Command", "DIR"]
COPY ./ app/
WORKDIR app
CMD [ "someapp", "somearg" ]
I have tried replacing cmd with powershell via
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN DIR
and the results are the same.
Thanks
Try running a dockerfile more like
FROM mcr.microsoft.com/windows/servercore/iis
RUN powershell -NoProfile -Command Remove-Item -Recurse
C:\inetpub\wwwroot*
WORKDIR /inetpub/wwwroot
COPY . /inetpub/wwwroot
maybe you gotta move your COPY command after the WORKDIR ?
Try different things out
Check to make sure you have update KB4532691 installed on your build machine (and host). The newest image of ltsc2019 (20/2020) has issues without it.
See https://hub.docker.com/_/microsoft-windows-servercore and https://support.microsoft.com/en-us/help/4542617/you-might-encounter-issues-when-using-windows-server-containers-with-t for more info
Related
I am very new to Docker, so perhaps I am just missing something simple, but I have not been able to figure out a way to accomplish this task.
I have a Dockerfile that looks like this:
FROM mcr.microsoft.com/windows:10.0.17763.3046-amd64
RUN mkdir "C:\Program Files (x86)\Austin Lane Technologies"
RUN mkdir "C:\Program Files (x86)\Austin Lane Technologies\ALMobile Suite"
WORKDIR "C:/Program Files (x86)/Austin Lane Technologies/ALMobile Suite/"
COPY ./BaseInstall/ProgramFiles/ .
WORKDIR "C:/Program Files (x86)/Austin Lane Technologies/ALMobile Suite/bin"
RUN "C:/Windows/Microsoft.NET/Framework/v4.0.30319/installutil.exe" /Logfile=SystemSvc.install.log SystemSvc.exe
RUN "C:/Windows/Microsoft.NET/Framework/v4.0.30319/installutil.exe" /Logfile=DataInterfaceSvc.install.log DataInterfaceSvc.exe
RUN "C:/Windows/Microsoft.NET/Framework/v4.0.30319/installutil.exe" /Logfile=DataSyncSvc.install.log DataSyncSvc.exe
RUN "C:/Windows/Microsoft.NET/Framework/v4.0.30319/installutil.exe" /Logfile=AUServerSvc.install.log AUServerSvc.exe
RUN "C:/Windows/Microsoft.NET/Framework/v4.0.30319/installutil.exe" /Logfile=ADExplorerSvc.install.log ADExplorerSvc.exe
This scripts builds the image:
docker build -t almobile:latest .
I then launch an Admin Powershell Window and do the following:
.\runalmobile_test.ps1, which contains:
docker run --user ContainerAdministrator --name master -v "C:\ALMobileSuiteProgramFiles\Master\ProgramFiles:C:\Program Files (x86)\Austin Lane Technologies\ALMobile Suite" -p 2089:2089 -p 2090:2090 -p 2091:2091 -p 2093:2093 -it almobile cmd.exe
The registry file I want to load resides in the C:\ALMobileSuiteProgramFiles\Master\ProgramFiles directory.
I am able to load the registry of the container with the contents of this file if I manually enter the regedit command from an Admin Powershell window, but what I want to do is to have the regedit import command automatically issued when the container starts. So, once the cmd.exe shell launches, I am in the C:\Program Files (x86)\Austin Lane technologies\ALMobile Suite\bin folder. If I manually issue the following command, all works:
regedit /i /s ..\ALMobile.reg
What is the best practice/way for me to automatically import this registry file at time of container startup? Is there a way to run the regedit command from the Dockerfile, or does this need to be executed from some alternate script?
I think you need to run the Registry file during the docker build step, not the docker run step. And use reg import instead of regedit. So in your Dockerfile, you would have something like this, assuming you are using Powershell:
COPY ALMobile.reg .
RUN Invoke-Command {reg import ALMobile.reg}
Below is my entrypoint.ps1 (PowerShell-script):
Set-Location -Path C:\nginx
& "C:\nginx\Configure-Nginx.ps1"
& "C:\nginx\nginx.exe"
I need to my Configure-Nginx.ps1 and node.exe were executed on docker run so I've put an entrypoint to my Dockerfile:
FROM nginx
# nginx is a custom image that's based on mcr.microsoft.com/windows/servercore:1809-KB5003171
COPY entrypoint.ps1 ./
COPY install/Configure-Nginx.ps1 /nginx/Configure-Nginx.ps1
ENTRYPOINT ["powershell", "entrypoint.ps1"]
However my container begins to restart each minute... Well, I've decided there is a some error in the script then I run this image manually with --entrypoint powershell and executed my script in the console directly: .\entrypoint.ps1. The script was frozen (cuz nginx was launched) and I could connect to my container from web-browser on the host machine... So everything works! Then why doesn't it work if I call my entrypoint from Dockerfile? What's difference? Maybe someone has met a similar problem...
P.S. The container is based on mcr.microsoft.com/windows/servercore:1809-KB5003171 with PowerShell v5.1.17763.1852
Firs make sure the script is available under the container root:
COPY entrypoint.ps1 /entrypoint.ps1
Then execute it either by -Command or -File:
ENTRYPOINT ["pwsh", "-Command", "/entrypoint.ps1"]
ENTRYPOINT ["pwsh", "-File","/entrypoint.ps1"]
I want to change the shell to bash.exefrom git-for-windows:
I have the docker file:
FROM mcr.microsoft.com/windows/servercore:1809
# $ProgressPreference: https://github.com/PowerShell/PowerShell/issues/2138#issuecomment-251261324
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RUN choco install -y git
RUN & 'C:/Program Files/Git/bin/sh.exe' -c "ls -al" #### << Passes
SHELL ["\"C:\\Program Files\\Git\\bash.exe\"", "-c"] #### << Passes
RUN ls -al #### << Crashes
Results in the third statement:
/usr/bin/bash: Files/Git/bin/sh.exe: No such file or directory
When I try to quote like the following
SHELL ["\"C:\\Program Files\\Git\\bash.exe\"", "-c"]
RUN ls -al
the build works, but I dont see any output from ls -al and I dont know if it really works?
How can I use bash.exe successfully? I am using docker for windows through WSL2 engine.
I ran into a similar issue using base image mcr.microsoft.com/windows:2004.
I am not very familiar with windows command prompt or powershell.
After you install git with chocolatey, update the system PATH environment variable. I used cmd for this because it was the first way I found on stack overflow and it has worked.
I have not tested the run command with a path containing a space so the below command might not work out of the box for you.
SHELL ["cmd", "/S", "/C"]
RUN setx path "C:\\Program Files\\Git\\bin;%path%"
With the system path environment variable updated, bash.exe is available at the command line.
SHELL ["bash.exe", "-c"]
RUN "ls -la"
ENTRYPOINT ["bash.exe"]
From everything I have read, I should be able to do this:
FROM mcr.microsoft.com/windows/servercore:ltsc2019
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ADD https://ddagent-windows-stable.s3.amazonaws.com/datadog-agent-7-latest.amd64.msi C:\datadog-agent-7-latest.amd64.msi
RUN Start-Process msiexec.exe -Wait -ArgumentList '/qn /i C:\datadog-agent-7-latest.amd64.msi APIKEY=abc123 /L*V C:\install.log'
It looks like it built correctly:
> docker build -t test .
Sending build context to Docker daemon 4.608kB
Step 1/4 : FROM mcr.microsoft.com/windows/servercore:ltsc2019
---> 71d3f266f3af
Step 2/4 : SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
---> Running in 1d931a586756
Removing intermediate container 1d931a586756
---> 277770d39d39
Step 3/4 : ADD https://ddagent-windows-stable.s3.amazonaws.com/datadog-agent-7-latest.amd64.msi C:/datadog-agent-7-latest.amd64.msi
Downloading [==================================================>] 146.9MB/146.9MB
---> 93223b61dad3
Step 4/4 : RUN Start-Process msiexec.exe -Wait -ArgumentList '/qn /i C:\datadog-agent-7-latest.amd64.msi APIKEY="abc123" /L*V C:\install.log'
---> Running in 619d7bb20f3b
Removing intermediate container 619d7bb20f3b
---> ddc461e4525a
Successfully built ddc461e4525a
Successfully tagged test:latest
But when I check in the container to see if it installed in C:\Program Files\Datadog, I am not seeing any of the files I am expecting from the installation.
I added the flag to give the install some extra logs (/L*V C:\install.log) but didn't see much in there. I have confirmed the msiexec command works on a Windows host, just not in the Docker build from what I can tell. Is there something simple that I'm missing?
I'm using Docker for Windows and building the docker image with a Dockerfile like this:
FROM mydockerhublogin/win2k16-ruby:1.0
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
RUN powershell -Command \
$ErrorActionPreference = 'Stop'; \
New-Item "HKLM:\Software\WOW6432Node\ExampleCom" -Force ; \
New-ItemProperty "HKLM:\Software\WOW6432Node\ExampleCom" -Name MenuLastUpdate -Value "test" -Force
RUN powershell -Command \
$ErrorActionPreference = 'Stop'; \
New-Item "HKLM:\Software\ExampleCom" -Force ; \
New-ItemProperty "HKLM:\Software\ExampleCom" -Name MenuLastUpdate -Value "test" -Force
# Run ruby script when the container launches
CMD ["C:/Ruby23-x64/bin/ruby.exe", "docker_ruby_test.rb"]
Note that I am adding some registry entries to the Windows registry which the code inside the container will access. While this method of adding registry entries is fine for a few entries, my requirement is to add dozens of entries required for my windows application. Is there a way to do this in a more concise manner?
Try creating a file for the your registry entry and copy that inside the container.
Then try running Invoke-Command -ScriptBlock {regedit /i /s C:\shared\settings.reg}
The following is the only way I could getting working using 4.8-windowsservercore-ltsc2019
COPY Registry/ChromeConfiguration.reg .
RUN reg import ChromeConfiguration.reg