This week I was trying to containerize an existing java application. Part of "installing" the application on the container required executing an PowerShell script in the container during the Image build. Based on the documentation here I thought i could add the following command to my dockerfile and it would work:
RUN install.ps1
However, when I went to build the image, it just hung on that step. I tried several other variations of the run command including:
RUN ["Powershell", ".\install.ps1"]
which resulted in the following error: '["Powershell"' is not recognized as an internal or external command,operable program or batch file.
RUN ["Powershell.exe", ".\install.ps1"] which returned the same error as above.
I was about to give up and move the PowerShell commands from the .ps1 file directly into the dockerfile itself as described here, but I had an "A HA!" moment and decided to give a simpler approach a try.
What finally worked was this line:
RUN "Powershell ./install.ps1"
This line results in the following being executed in the container
cmd /S /C Powershell ./install.ps1
While this seems pretty straightforward, I wasn't able to find any examples of dockerfiles with people calling .ps1 files directly so hopefully this saves someone some time.
Happy Coding!
RUN install.ps1
However, when I went to build the image, it just hung on that step. I tried several other variations of the run command including:
RUN ["Powershell", ".\install.ps1"]
which resulted in the following error: '["Powershell"' is not recognized as an internal or external command,operable program or batch file.
RUN ["Powershell.exe", ".\install.ps1"] which returned the same error as above.
I was about to give up and move the PowerShell commands from the .ps1 file directly into the dockerfile itself as described here, but I had an "A HA!" moment and decided to give a simpler approach a try.
What finally worked was this line:
RUN "Powershell ./install.ps1"
This line results in the following being executed in the container
cmd /S /C Powershell ./install.ps1
While this seems pretty straightforward, I wasn't able to find any examples of dockerfiles with people calling .ps1 files directly so hopefully this saves someone some time.
Happy Coding!
Comments
Post a Comment