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:
FROM microsoft/dotnet-framework
COPY run.ps1 /
ENTRYPOINT [ "powershell.exe", "C:\\run.ps1" ]
The contents of run.ps1
(uber-simplified for this question):
gci
write-host "looks like everything is good!"
Then, I ran the following commands:
# Build the Docker image
docker build --rm -t testdockerps .
# Create/run container using above image
docker run -it testdockerps
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:
ENTRYPOINT
JSON array? Should I be using the SHELL
command in the Dockerfile?Step 1: Create a script.sh file and copy the following contents. Step 2: You should have the script.sh is the same folder where you have the Dockerfile. Create the Dockerfile with the following contents which copy the script to the container and runs it part of the ENTRYPOINT using the arguments from CMD.
Once Docker is installed, go ahead and open a console window in your operating system. Then look at the Docker Hub page for PowerShell. Notice the command to pull a container with PowerShell to your computer is docker pull mcr.microsoft.com/powershell.
In Dockerfiles, an ENTRYPOINT instruction is used to set executables that will always run when the container is initiated. Unlike CMD commands, ENTRYPOINT commands cannot be ignored or overridden—even when the container runs with command line arguments stated.
Yes you can specify powershell as default shell like below on top of DOCKERFILE
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"]
I'm not sure you can do anything about time it takes to spin down your VM
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