dockerfile MULTIPLE commands or entrypoints–Powershell and IIS as ENTRYPOINTS in Docker Compose
Typically, dockerfiles require a single entrypoint or single command. In fact, multiple CMD instructions are ignored and only the final CMD is executed. By now, you should know that entrypoint and COMMAND instructions can be placed in your docker-compose.yml – instead of your dockerfiles. I prefer this approach since this keeps both files clean and more maintainable.
What do you do if you require more than one command to execute when your container starts up?
The answer is simple – but getting it work was not trivial. The idea is to wrap up those tasks in powershell scripts (say bootstrap.ps1) – and assign the ENTRYPOINT to the bootstrap script.
Why was this a challenge to get working?
The challenge wasn’t with assigning the Powershell script as the startup ENTRYPOINT command. That worked just fine. The challenge was to do that – AND to restart IIS (or whatever webserver/aspnet dll / app entrypoint) – your application’s true entrypoint – at the same time. Again, the fact that you can only assign ONE ENTRYPOINT command, kept me searching for the answer.
It turns out you can concatenate your ENTRYPOINT commands – provided you start with POWERSHELL – and use Powershell concatenation as shown in the last line below.
version: '3.7' services: web: env_file: .\variables.env build: context: .\web dockerfile: Dockerfile ports: - "80" - "443:443" security_opt: - credentialspec=file://mywebsite.json hostname: mywebsite volumes: - c:\Data:c:\Data - c:\certs:c:\certs entrypoint: cmd /c "powershell \bootstrap.ps1 & C:\\ServiceMonitor.exe w3svc"
Summary
Dockerfile instructions are concise and thus, deceptively simple. There seem to be limitations imposed by docker, but it turns out, with a little powershell, these limitations can be easily overcome. This post describes a way to assign multiple startup , entrypoint commands – something I found, a lot of people struggling with.
Leave a Reply