Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RUN Powershell Script in Docker Container From Host Powershell Script

I have a powershell script in host which copy some files and starts the container.

#Copy File
docker cp "D:\addApplication.ps1" website:/inetpub/wwwroot/

#Start Container
docker start website
Write-Host 'Process has started'

#Execute Container
docker exec -ti website powershell

#Run Script
Invoke-Expression "C:\inetpub\wwwroot\addApplication.ps1"

Second last command executes fine but last command will only execute when I exit the container session and returns error(File Not Found which is because it finds that file on host)

Question: Is there anyway I can execute the command in container session from the script. Or execute any command from script in any process(confused)

Any help is appreciated.

Thanks

like image 696
Usama Saleem Avatar asked Dec 15 '17 08:12

Usama Saleem


People also ask

Can PowerShell run in docker?

Please follow Docker's official instructions to install docker correctly. The release containers derive from the official distribution image, then install dependencies, and finally install the PowerShell package. These containers live at hub.docker.com/r/microsoft/powershell.

Can I run Windows application in docker container?

To switch to Windows containers in Docker, right-click the Docker icon, and select Switch to Windows containers. To use the command line to switch between containers, run & $Env:ProgramFiles\Docker\Docker\DockerCli.exe -SwitchDaemon .

How do I run a PowerShell script from PowerShell?

To run a script, open a PowerShell window, type the script's name (with or without the . ps1 extension) followed by the script's parameters (if any), and press Enter.


Video Answer


1 Answers

Do not use the -ti flags to start an interactive session, just execute the script directly via the docker exec command

docker exec website powershell -command "C:\inetpub\wwwroot\addApplication.ps1"
like image 110
arco444 Avatar answered Sep 25 '22 06:09

arco444