5

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

4
  • Invoke-Expression is not the correct command to run a script. You should use & "C:\inetpub\wwwroot\addApplication.ps1" Commented Dec 15, 2017 at 9:21
  • the problem is...when it executes the second last command it starts the container session and did not execute the last command until I exit the session...I want to run the last command in container session...not in the host Commented Dec 15, 2017 at 10:15
  • 1
    Then don't run interactively. Try docker exec website powershell -command "C:\inetpub\wwwroot\addApplication.ps1" Commented Dec 15, 2017 at 10:21
  • Thanks for the quick response. It worked... Commented Dec 15, 2017 at 10:28

1 Answer 1

7

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"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.