Reputation: 161
I try these below commands in dockerfile but it didnot run the script.so are there any other commands for running the ps script in dockerfile?
ADD Windowss.ps1 .
CMD powershell .\Windowss.ps1;
Upvotes: 16
Views: 55315
Reputation: 31
I tried this one and it worked,
FROM mcr.microsoft.com/powershell
WORKDIR /app
COPY . /app
CMD ["pwsh", "-File", "<your_powershellscript>"]
Here we need to mention the executable as pwsh
not powershell
, For your reference attaching the Github code link: Here(line: 39) Here (line: 56)
Upvotes: 1
Reputation: 2441
I had a similar problem which I solved by using the shell directive.
FROM mcr.microsoft.com/windows/servercore:20H2 AS PS
SHELL ["powershell"]
RUN Write-Host "Hello from docker! Today is $(Get-Date)"
Edit: Just noticed the answer above has a bit better of a command than mine. Upvote it! https://stackoverflow.com/a/48804143/190831
Upvotes: 1
Reputation: 2814
To run a PS1 script file, you can do something like this:
SHELL ["cmd", "/S", "/C"]
RUN powershell -noexit "& ""C:\Chocolatey\lib\chocolatey.0.10.8\tools\chocolateyInstall.ps1"""
You can also do:
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
WORKDIR C:\
RUN .\install_pfx.ps1
Upvotes: 53
Reputation: 2304
You can use RUN
.
You can RUN poweshell commands using
RUN powershell -Command Add-WindowsFeature Web-Server
Upvotes: 8
Reputation: 1490
Yes, there is another command. ENTRYPOINT ["executable", "param1", "param2"]
is a command that, according to the documentation, will make the container to run the executable on its start. It can be used alongside with CMD
.
Upvotes: 1