使用参数在Docker Windows容器中运行Apache

时间:2018-11-07 07:08:15

标签: windows apache docker

主要问题:

如何使用Dockerfile中的CMD命令将参数传递给Windows版Docker(Windows容器)中的Apache?

背景

我正在尝试对运行Apache门户的项目之一进行docker化,通常使用以下命令来执行该项目:

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

到目前为止,我设法建立了一个Dockerfile来安装和运行它,但是由于它没有CMD而在运行时立即终止了该容器。 Dockerfile看起来像这样:

# Starts from the windows server core
FROM microsoft/windowsservercore

# Install Visual C++ Redistributable for Visual Studio 2012 Update 4 x86
ADD http://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU3/vcredist_x86.exe 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 https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x86.exe 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

这有效,但仅在使用以下命令运行时才有效,我认为这不是永久解决方案,因为我无法在docker-compose中使用它:

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

如果我这样做,则可以通过localhost:6007访问Mini Server。

但是,我想要的是使用CMD命令使之工作。

我尝试了以下方法:

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

即使没有-it powershell后缀,这也会在运行时创建持久容器。但是,它不允许我作为先前的解决方案访问MiniServer,而是显示以下错误消息,大概是因为缺少“ -k start -n CompanyMiniServer”参数:

Forbidden

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.

因此,我尝试了多种添加参数的方法,但都没有成功:

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" ]

所有这些都只是导致容器再次自动终止。

0 个答案:

没有答案