10

I'm trying to use Azure App Service Containers to host Azure DevOps Pipeline agents. I've got everything working in the sense that my agent runs great locally using Docker Desktop, but when I publish the image to the App Service, the startup command is never executed. I'm forced to get a console in the container and manually run the powershell script, which then works as expected.

Here is my docker file:

FROM mcr.microsoft.com/windows/servercore:ltsc2019
RUN powershell Install-PackageProvider -Name NuGet -Force
RUN powershell Install-Module PowershellGet -Force
RUN powershell Install-Module -Name Az -Repository PSGallery -Force
RUN powershell Install-Module -Name Az.Tools.Migration -Repository PSGallery -Force
RUN powershell Enable-AzureRMAlias
WORKDIR /azp
COPY start.ps1 .
CMD powershell "c:\azp\start.ps1"

The deployment center logs show no errors. It's as if the CMD is never run.

RMD
  • 3,421
  • 7
  • 39
  • 85
  • In the question, you mention "as if the CMD is never run", has this been verified? E.g. by a log entry at the beginning of the start.ps1 script? Is it completely certain that the script does not run? At least one of the ENTRYPOINT or CMD should be defined. Having no ENTRYPOING or CMD is not allowed. If you have also experimented with ENTRYPOINT, as indicated by existing answers and CMD. The cause of the observed behaviour might not be the CMD or ENTRYPOINT not running. – Spyros K Aug 26 '22 at 11:20

3 Answers3

0

please replace powershell CMD line as below -

CMD ["powershell.exe", "-File", "c:\azp\start.ps1"]

also its always good to use the full path for the exe if its not exist in PATH.

also use workdir as below -

FROM mcr.microsoft.com/windows/servercore:ltsc2019
RUN powershell Install-PackageProvider -Name NuGet -Force
RUN powershell Install-Module PowershellGet -Force
RUN powershell Install-Module -Name Az -Repository PSGallery -Force
RUN powershell Install-Module -Name Az.Tools.Migration -Repository PSGallery -Force
RUN powershell Enable-AzureRMAlias
WORKDIR c:\azp
COPY start.ps1 .
CMD ["powershell.exe", "-File", "c:\azp\start.ps1"]
  • Thanks for the suggestion. Unfortunately this doesn't appear to have made a difference. Here are the startup logs from the app service: Container has no CMD and/or ENTRYPOINT defined. It will be started without executing an entrypoint. – RMD Aug 11 '22 at 20:13
0

I did not try building your docker image, but you should investigated on how ENTRYPOINT is defined, and so how it interacts with CMD.

Look at the Official Guide.

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
0

According to docker documentation, if you want a command to be always executed you must pass it in ENTRYPOINT and not in CMD. When you pass your command in CMD, it can be overridden by an argument when the container is executed.

CMD will be overridden when running the container with alternative arguments.

So I don't know how you run your container but I advise you to try to pass your script in ENTRYPOINT.

Something like that:

FROM mcr.microsoft.com/windows/servercore:ltsc2019
RUN powershell Install-PackageProvider -Name NuGet -Force
RUN powershell Install-Module PowershellGet -Force
RUN powershell Install-Module -Name Az -Repository PSGallery -Force
RUN powershell Install-Module -Name Az.Tools.Migration -Repository PSGallery -Force
RUN powershell Enable-AzureRMAlias
WORKDIR c:\azp
COPY start.ps1 .

ENTRYPOINT ["powershell.exe", "c:\\azp\\start.ps1"]
Mickael Rahmine
  • 372
  • 1
  • 7