So I'm trying to build a Docker Image based on windows that will run two windows services.
This builds an image as expected but when I run the image I don't see the two windows services present and I don't see the services file with my edit in it.
I've searched and searched and have not found much help with Docker and Windows mostly everything is linux based help. I will need to expose tcp/ip ports as well for the 2 services.
Here is what I have in my DockerFile so far
FROM mcr.microsoft.com/windows/servercore:ltsc2019
COPY bin C:\Company\App\bin
COPY Installers C:\Company\Installers
WORKDIR "C:\Company\Installers"
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN Start-Process 'C:\Company\Installers\msodbcsql.msi' '/qn' -PassThru | Wait-Process;
RUN echo "apprecv 22804/tcp #Company AppRecv service" >> c:\windows\system32\drivers\etc\services
WORKDIR "C:\Company\App\bin"
RUN Start-Process 'SC.exe' -Wait -ArgumentList 'CREATE "App Poll" binpath="C:\Company\App\bin\apppoll.exe" start=disabled';
RUN Start-Process 'SC.exe' -Wait -ArgumentList 'DESCRIPTION "App Poll" "Pulls Data"';
RUN Start-Process 'SC.exe' -Wait -ArgumentList 'CREATE "App Receive" binpath="C:\Company\App\bin\apprecv.exe" start=disabled';
RUN Start-Process 'SC.exe' -Wait -ArgumentList 'DESCRIPTION "App Receive" "Receives Data"';
I first run this to build the image
docker build -t app .
Then when I run
docker run -it app:latest powershell.exe
I first check the services file and don't see it changed and then when I call Get-Services I don't see the windows services installed.
What am I missing here? Eventually, I plan to run this in Azure.
Related
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.
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"]
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.
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"]
I need to use mcr.microsoft.com/windows:10.0.17763.2928 docker image. How to install .net framework v4.8 into this container? I use following docker file. I upload ndp48-x86-x64-allos-enu.exe (.net framework v4.8 installer) into container, and then install it by command line, but it doesn't work. I got the "404 - File or directory not found."
FROM mcr.microsoft.com/windows:10.0.17763.2928
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET45 -All
WORKDIR c:/
COPY ndp48-x86-x64-allos-enu.exe .
RUN Start-Process -FilePath 'C:/ndp48-x86-x64-allos-enu.exe' -ArgumentList '/quiet', '/NoRestart', '/L*V C:/net48log.log' -Wait
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .
My docker image is from mcr.microsoft.com/powershell:latest which has powershell installed. Why do I get this error when build docker image: /bin/sh: 1: Install-Module: not found
Below is my dockerfile:
FROM mcr.microsoft.com/powershell:latest
RUN Install-Module dbatools -Force
I can run the command Install-Module dbatools -Force when I manually launch a container from mcr.microsoft.com/powershell:latest. Why can't I run it from building the image? Does it have a different context? If it uses my localhost context, does it mean I need to install powershell on my Mac OS?
If I want to run a powershell script as ENTRYPOINT, how can I specify it?
you can use SHELL directive in Dockerfile:
escape=`
SHELL ["powershell","-command"]
RUN New-Item -ItemType Directory C:\Example
see more here
I'm currently running a Windows Server 2019 host, and I'm trying to get Visual Studio Build Tools and SSDT installed on a windowsservercore:lts2019 image. I am able to do successful quiet installs of both if I mount the directory when I run the container with docker run -it -v <src>:<dst> image:tag powershell and run the .exes with quiet flags, however I need the installed files to be available within the container so I am trying to do this install within the Dockerfile. Here's what I have:
FROM mcr.microsoft.com/windows/servercore:ltsc2019
SHELL ["powershell.exe", "-ExecutionPolicy", "Bypass", "-Command"]
RUN (New-Object System.Net.WebClient).Downloadfile('http://javadl.oracle.com/webapps/download/AutoDL?BundleId=210285', 'C:\\jre-8u91-windows-x64.exe')
RUN Start-Process -filepath 'C:\\jre-8u91-windows-x64.exe' -passthru -wait -argumentlist "/s,INSTALLDIR=$env:JAVA_HOME,/L,install64.log"
RUN del 'C:\\jre-8u91-windows-x64.exe'
RUN $env:PATH = $env.JAVA_HOME + '\\bin;' + $env:PATH; \
[Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine);
COPY ./vs_setup.exe .
COPY ./SSDT-Setup-ENU.exe .
RUN vs_setup.exe -q --norestart --add Microsoft.VisualStudio.Product.Professional
RUN SSDT-Setup-ENU.exe /install installvssql:ssdt /quiet /wait /norestart
RUN SSDT-Setup-ENU.exe /install INSTALLALL /quiet /wait /norestart
CMD ["powershell.exe", "-nologo"]
That reports that the COPY commands ran successfully, however once the step to run the .exes that I'd tried copying over is run, I get the error that 'vs_setup.exe' is not a recognized cmdlet, function, etc.
I do a docker run -it image:tag powershell, I can see that C:\installs exists but it's empty. The .exes that I'm trying to copy are in the same directory level as the Dockerfile being ran. Is there anyway to get these copied and installed in the Dockerfile?
Edit:
I've updated the Dockerfile to show that the Java stuff isn't changing directories, or at least shouldn't be. The folder structure is:
Directory: C:\projects
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 6/25/2019 3:13 PM 4291 Dockerfile
-a---- 6/27/2019 10:54 AM 1608400 SSDT-Setup-ENU.exe
-a---- 5/16/2019 3:20 PM 1286728 vs_setup.exe
As much as I would like this to work I think that I'll need to mount a volume and install these manually, then use multi-stage builds and docker commit to create a new image off of the post-install container. I'll keep this updated with what works.
I am using Docker for Windows and am trying to convert a Asp.NET MVC 5 to a container. The one remaining roadblock is that I need the ASPNET State server running. I can start up the service through the interactive terminal and it works just fine, but am unable to get the container to start the service automatically. I've tried using CMD, ENTRYPOINT, and RUN, but from what I gather some of these will only execute the command while the image is building, not when the container starts.
My DOCKERFILE is as follows
FROM microsoft/aspnet:4.7.1-windowsservercore-1709
ARG source
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .
CMD powershell -Command \
Set-Service aspnet_state automatic; \
Start-Service -name "aspnet_state"; \
EXPOSE 1433
Instead of using CMD, I used RUN to commit the command to the image, and used multiple RUN commands:
# Enable Session State Server
RUN powershell -Command Set-Service aspnet_state -startuptype automatic
RUN powershell -Command Stop-Service aspnet_state
RUN powershell -Command Start-Service aspnet_state
RUN powershell -Command Set-ItemProperty Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters -Name AllowRemoteConnection -Value 1
You simply need the following code after you have properly installed the service into the image.
ENTRYPOINT ["powershell"]
CMD Start-Service \""MyWindowsServiceName\"";
NOTE: The name of a windows service may be different to its executable name. You need the windows service name here, not the executable name.