本文介绍了Windows-Docker CMD无法执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我生命中,我似乎无法在运行容器时执行配置脚本。在接下来的工作中,我需要将参数传递给docker run命令,以替换多个容器部署中的 hiiii和 123。

For the life of me, I cannot seem to get my provisioning script to execute when I run my container. Down the road, I will need to pass in arguments to the docker run command to replace 'hiiii' and '123' for multiple container deployments.

这是我的docker文件

This is my docker file

FROM microsoft/aspnet:3.5-windowsservercore-10.0.14393.1198

SHELL ["powershell", "-Command", "$ErrorActionPreference = ‘Stop’; $ProgressPreference = ‘SilentlyContinue’;"]

COPY *.ps1 /Container/

COPY ["wwwroot", "/inetpub/wwwroot"]
COPY ["Admin", "/Program Files (x86)Admin"]
COPY ["Admin/web.config", "/Program Files (x86)/Admin/web_default.config"]

#ENTRYPOINT ["powershell"]
CMD ["powershell.exe", -NoProfile, -File, C:\Container\Start-Admin.Docker.Cmd.ps1 -Parm1 ‘Hiiii’ -parm2 ‘123’]

我还尝试了CMD的shell版本,如下所示:

I have also tried the shell version of CMD as follows

CMD powershell -NoProfile -File C:\Container\Start-Admin.Docker.Cmd.ps1 -Parm1 ‘Hiiii’ -Parm2 ‘123’

这是我正在使用的命令。

This is the command I am using.

docker image build -t image:v1:v1 .
docker run --name container -p 8001:80 -d image:v1

之后创建并运行容器后,我看到脚本未运行或失败。但是,我可以在容器中执行powershell并手动运行脚本,它可以正常工作,并且可以看到所需的所有更改。

After I create and run the container I see that the script did not run, or failed. However, I can exec into powershell on the container and run the script manually and it works fine and I see all the changes that I need.

docker exec --interactive --tty container powershell
C:\Container\Start-Admin.Docker.Cmd.ps1 -Parm1 ‘Hiiii’ -Parm2 ‘123’

我对我所缺少的CMD感到茫然。

I am just at a loss as to what I am missing regarding CMD.

谢谢!

推荐答案

我能够按照我希望的方式工作。尽管我仍在配置脚本中制定一些细节,但这还是我最终从Docker方面获得所需结果的原因。

I was able to get it working the way I had hoped. Though I am still working out some details in the provisioning script, this is how I ended up getting the result I wanted from the docker side of things.

FROM microsoft/aspnet:3.5-windowsservercore-10.0.14393.1198

#The shell line needs to be removed and any RUN commands need to be immediately proceeded by 'powershell' eg RUN powershell ping google.com
#SHELL ["powershell", "-Command", "$ErrorActionPreference = ‘Stop’; $ProgressPreference = ‘SilentlyContinue’;"]

COPY *.ps1 /Container/

COPY ["wwwroot", "/inetpub/wwwroot"]
COPY ["Admin", "/Program Files (x86)Admin"]
COPY ["Admin/web.config", "/Program Files (x86)/Admin/web_default.config"]

ENV myParm1 Hiiii
ENV myParm2 123
ENTRYPOINT ["powershell", "-NoProfile", "-Command", "C:\\Container\\Start-Admin.Docker.Cmd.ps1"]
CMD ["-parm1 $Env:myParm1 -parm2 $Env:myParm2"]

docker run命令如下

The docker run command looks like this

docker run -d -p 8001:80 -e "myParm1=byeeeee" --name=container image:v1

我希望这会对我船上的其他人有所帮助。感谢所有答案!

I hope this helps someone else that is in my boat. Thanks for all the answers!

这篇关于Windows-Docker CMD无法执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 15:10