问题描述
我在主机中有一个Powershell脚本,可以复制一些文件并启动容器.
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)
感谢您的帮助.
谢谢
推荐答案
请勿使用 -ti
标志启动交互式会话,只需直接通过 docker exec
命令
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"
这篇关于从主机Powershell脚本运行Docker容器中的Powershell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!