How do I specify a PowerShell script as a Docker container entry point?

Question:

I need to run a [Windows] Docker container as an executable, running a rather involved PowerShell script (invoking Java and .NET applications) and exiting. Docker documentation suggests using ENTRYPOINT for this purpose. So I went ahead and created a Dockerfile with the following contents:

The contents of run.ps1 (uber-simplified for this question):

Then, I ran the following commands:

The container ran successfully, displaying the contents of C:\ followed by the message – looks like everything is good!.

I have a couple of questions based on what my observations:

  1. What is the default shell for a Windows based Docker container? Is there any way to set it to PowerShell, so I don’t have to specify “powershell” as the first element of the ENTRYPOINT JSON array? Should I be using the SHELL command in the Dockerfile?
  2. Creating and running the container takes about 3-4 seconds which is somewhat understandable, but after the PS1 script completes, it takes nearly a questionable 10 seconds for the container to exit and return to the command prompt. What may be the cause of this delay?

Answer:

Yes you can specify powershell as default shell like below on top of DOCKERFILE

I’m not sure you can do anything about the time it takes to spin down your VM

Source:

How do I specify a PowerShell script as a Docker container entry point? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply