Search code examples
docker-composedockerfiledocker-machinedocker-for-windowsdocker-container

Running an exe file in windows container using docker


I want to run an exe file on window container using Docker. My exe accepts parameters. New file gets created in predefined directory

ie:- Test.exe -f1=file1.txt -f2=file2.txt

**Output** :
Writing file file1.txt
Successfully created file file1.txt 
Writing file2 file2.txt
Successfully created file file2.txt
Enjoy!!

My docker file looks like below

FROM microsoft/aspnet:3.5-windowsservercore-10.0.14393.1715 
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
Copy Test.exe ./TestFolder/
WORKDIR /TestFolder
ENTRYPOINT ["Test.exe"]
CMD ["f1=file1.txt","f2=file2.txt"]

I build the image and run the container

docker build -t image1 .
docker run -it image1

Once the container runs I get the exact above output but when I login to container machine using scripts, I don't see any file created in the predefined path. Am I missing out anything ? Is this the correct way to run exe file on windows base image?

Any advice is appreciated. Thanks


Solution

  • Found out that the exe was running fine and file was created. The way I logged into the container was wrong.

    I should have used:

    docker exec -it containername powershell
    

    This runs a new instance of a non-existing image

    docker run -it --entrypoint powershell imagename