2

For the life of me, I cannot seem to get my provisioning script to execute when I run my container. Down the road, I will need to pass in arguments to the docker run command to replace 'hiiii' and '123' for multiple container deployments.

This is my docker file

FROM microsoft/aspnet:3.5-windowsservercore-10.0.14393.1198

SHELL [“powershell”, “-Command”, “$ErrorActionPreference = ‘Stop’; $ProgressPreference = ‘SilentlyContinue’;”]

COPY *.ps1 /Container/

COPY [“wwwroot”, “/inetpub/wwwroot”]
COPY [“Admin”, “/Program Files (x86)Admin”]
COPY [“Admin/web.config”, “/Program Files (x86)/Admin/web_default.config”]

#ENTRYPOINT [“powershell”]
CMD [“powershell.exe”, -NoProfile, -File, C:\Container\Start-Admin.Docker.Cmd.ps1 -Parm1 ‘Hiiii’ -parm2 ‘123’]

I have also tried the shell version of CMD as follows

CMD powershell -NoProfile -File C:\Container\Start-Admin.Docker.Cmd.ps1 -Parm1 ‘Hiiii’ -Parm2 ‘123’

This is the command I am using.

docker image build -t image:v1:v1 .
docker run --name container -p 8001:80 -d image:v1

After I create and run the container I see that the script did not run, or failed. However, I can exec into powershell on the container and run the script manually and it works fine and I see all the changes that I need.

docker exec --interactive --tty container powershell
C:\Container\Start-Admin.Docker.Cmd.ps1 -Parm1 ‘Hiiii’ -Parm2 ‘123’

I am just at a loss as to what I am missing regarding CMD.

Thanks!

Drew Fleming
  • 327
  • 4
  • 7

2 Answers2

2

I was able to get it working the way I had hoped. Though I am still working out some details in the provisioning script, this is how I ended up getting the result I wanted from the docker side of things.

FROM microsoft/aspnet:3.5-windowsservercore-10.0.14393.1198

#The shell line needs to be removed and any RUN commands need to be immediately proceeded by 'powershell' eg RUN powershell ping google.com
#SHELL [“powershell”, “-Command”, “$ErrorActionPreference = ‘Stop’; $ProgressPreference = ‘SilentlyContinue’;”]

COPY *.ps1 /Container/

COPY [“wwwroot”, “/inetpub/wwwroot”]
COPY [“Admin”, “/Program Files (x86)Admin”]
COPY [“Admin/web.config”, “/Program Files (x86)/Admin/web_default.config”]

ENV myParm1 Hiiii
ENV myParm2 123
ENTRYPOINT ["powershell", "-NoProfile", "-Command", "C:\\Container\\Start-Admin.Docker.Cmd.ps1"]
CMD ["-parm1 $Env:myParm1 -parm2 $Env:myParm2"] 

The docker run command looks like this

docker run -d -p 8001:80 -e "myParm1=byeeeee" --name=container image:v1

I hope this helps someone else that is in my boat. Thanks for all the answers!

Drew Fleming
  • 327
  • 4
  • 7
0

You can give this a try. ARG passes the variable to shell accessible via PS $env: variable.

ARG parmOne=Hiiii
ARG parmTwo=123

# Run a native PowerShell session and pass the script as a command.
RUN ["powershell", "-NoProfile", "-Command", "C:\\Container\\Start-Admin.Docker.Cmd.ps1 -Parm1 $env:parmOne -parm2 $env:parmTwo"]
ekeeling
  • 361
  • 1
  • 7
  • There is more to the story - eventually, I am going to need to replace 'hiii' and '123' with environment variables passed from docker run. Since I need to pass the vars on at this time, a RUN command cannot be used as that is part of the docker build process. A CMD command is supposed to execute the CMD part of the dockerfile on docker run but it is not doing so. – Drew Fleming Sep 29 '17 at 19:07
  • That generally works for me as long as I don't need the variables to be stored post build. If you need the variables stored post build, you can use PowerShell to add them as persistent variables. – ekeeling Sep 29 '17 at 20:04
  • Yeah I do need to update after build. These values are going to be client specific things like connection strings. The idea is to use different containers of the same image with different config settings. – Drew Fleming Sep 29 '17 at 20:21
  • @DrewFleming - why not define the environment variables you want to use in the Dockerfile and pass them in using docker run. Also, if your SHELL is already set to PowerShell then in your CMD instruction you don't need to reference the full powershell.exe again, just reference your script file and pass it the arguments you require using $env:{environment variable name} – Chris Lawrence Sep 30 '17 at 22:37