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
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.
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 .
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With