1

I have made a few containers (which run in the Unix environment where the entrypoint is a script file. These script files usually manage some configuration and then carries on executing the CMD by using the exec "$@". While creating/testing such an image I usually return to the command prompt so I manually can assert the configurations. This works fine. However, today I was making a similar image but based on the windows container (microsoft/nanoserver) and here I ran into a few problems.

1) I made a powershell script to do the configuration but in powershell I can't use the exec "$@" to relay the execution to the CMD. What is the equivalent in a windows container?

2) If I create an image based on microsoft/nanoserver and just copy in some files you will stay in interactive mode (if you run the container with -it params of course). But as soon as I point the ENTRYPOINT to a powershell script, the container will terminate immediately after running the script, even though I append a cmd to the run command.

So basically my question is: How do I get it to enter the command prompt after executing a script? (with windows container).

Galtrold
  • 75
  • 9
  • 1
    Below works fine for me. Running a script and returning prompt # escape=` FROM microsoft/nanoserver SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"] entrypoint powershell.exe {Write-output "hello"}; powershell.exe – Gregory Suvalian Sep 09 '17 at 16:53
  • Thanks Gregory, I got it working as i wanted. However I have no idead of what SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"] does. Also its a little strange that we need to have two powershell.exe statements in the ENTRYPOINT. – Galtrold Sep 14 '17 at 21:30
  • @Galtrold You don't. With `SHELL ["powershell"]`, your `ENTRYPOINT` is run by powershell.exe, so it can be any valid Powershell expression. You can run the script file directly or `Invoke-Expression` it. – jmlane Mar 07 '18 at 15:55
  • Consider this docker container that uses a script as an entrypoint https://github.com/PhilippHeuer/docker-gitlab-powershell – spuder Apr 09 '18 at 22:08

1 Answers1

-1

this question is similar to How to keep WIndows Container running?

if you add at the end of your dockerfile

ping -t localhost

it should leave it running (...unless there is some other errors in the file, of course)

JulioCT
  • 1,057
  • 8
  • 7