Run apache in Docker Windows container using parameters

Hello everyone,

I am trying to dockerize one of our Projects running an Apache portal, which usually gets executed using the following command:

C:\Company\MiniServer\Apache2.4\bin\CompanyMiniServer.exe -k start -n CompanyMiniServer

Thus far, I managed to set up a Dockerfile that installs and runs this, but terminates the container immediately when run due to it not having an CMD. That Dockerfile looks like this:

# Starts from the windows server core
FROM microsoft/windowsservercore

# Install Visual C++ Redistributable for Visual Studio 2012 Update 4 x86
ADD C:/installers/vc2012/vcredist_x86.exe
RUN C:\installers\vc2012\vcredist_x86.exe /quiet /install

# Install Visual C++ Redistributable for Visual Studio 2015 Update 3 x86
ADD C:/installers/vc2015/vc_redist.x86.exe
RUN C:\installers\vc2015\vc_redist.x86.exe /quiet /install

# Add the Files
ADD Company C:/Company/

# Sets Shell Mode to use PowerShell
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# Installs and starts the Company Mini Server via Powershell Script 
RUN C:\Company\InstallAndStartMiniServer.ps1

This works, but only when run using the following command, which I consider not to be a permanent solution, since I can’t use it in docker-compose:

docker run -p 6007:6007 -p 6008:6008 --name companyminiserver_container -d -it companyminiserver powershell

If I do it like this, I can then access the Mini Server via localhost:6007.

However, what I want is to make this work using the CMD command.

I have tried the following:

CMD [ "C:\\Company\\MiniServer\\Apache2.4\\bin\\CompanyMiniServer.exe" ]

This creates a persistent container when run even without the -it powershell suffix. However, it does not let me access the MiniServer as the previous solution, and instead displays the following error message, presumably because the “-k start -n CompanyMiniServer” parameters are missing:


You don't have permission to access /portal/ on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

So I tried to add the parameters in a variety of ways, but neither of them were successful:

CMD [ "C:\\Company\\MiniServer\\Apache2.4\\bin\\CompanyMiniServer.exe","-k start","-n CompanyMiniServer" ]
CMD [ "C:\\Company\\MiniServer\\Apache2.4\\bin\\CompanyMiniServer.exe","-k start -n CompanyMiniServer" ]
CMD [ "C:\\Company\\MiniServer\\Apache2.4\\bin\\CompanyMiniServer.exe","-k","start","-n CompanyMiniServer" ]
CMD [ "C:\\Company\\MiniServer\\Apache2.4\\bin\\CompanyMiniServer.exe","-k","start","-n","CompanyMiniServer" ]
CMD [ "C:\\Company\\MiniServer\\Apache2.4\\bin\\CompanyMiniServer.exe -k start -n CompanyMiniServer" ]

All of these simply caused the container to auto-terminate again.

My main question is: How can I pass parameters to Apache in Docker for Windows (Windows Containers) using the CMD command in a Dockerfile? There probably is an easy way to do that, but I am still new to Docker, and thus still confused about many things, such as the proper use of CMD.

Can somebody please help me with this? Any feedback would be greatly appreciated.

Thanks in advance,
Kira Resari

Your first attempt should be fine. You may need to set the permissions of the Web server’s document root, though, to get around the 403 error.

Well, by now I have settled to using the following workaround to keep the container alive:

CMD ping -t localhost

This might not be the intended or ideal solution, but at the very least it’s a solution that works, and also works when using docker-compose.