首页 > 解决方案 > Docker CMD 和 Mount 相互排斥

问题描述

  1. 用例:我有一个小的dot.net core sdk 3.0 应用程序,它应该在容器内运行。
  2. 用例:我还将容器文件夹挂载到 Windows 文件系统

图像的 Dockerfile 如下所示:

FROM mcr.microsoft.com/dotnet/core/sdk:3.0

#SET WORKING DIRECTORY
WORKDIR /app

#COPY ALL AND RESTORE
COPY . .
RUN dotnet restore "Modeling\\ModellingMicroServices.sln"

#INSTALL SOFTWARE
SHELL ["cmd", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN Start-Process 'software\\graphviz-2.38.msi' '/qn' -PassThru | Wait-Process;

#CMD SDK3.0
CMD ["Modeling\\MicroServiceModelCompilerCore\\bin\\Debug\\netcoreapp3.0\\MicroServiceModelCompilerCore.exe", "watcher", "Modeling\\MicroServiceModelCompilerCore\\bin\\Debug\\netcoreapp3.0"]

分开的U1U2工作正常。

U1:

docker build -t mms .
docker run --name mms-c mms

U2:

docker build -t mms .
docker run -d --name mms-c --mount type=bind,source="C:/Users/user/Desktop/ModellingMicroServices/mount",target="C:/app/Modeling/MicroServiceModelCompilerCore/bin/Debug/netcoreapp3.0" mms

问题:

U2仅在我不在CMDdockerfile 末尾调用命令时才有效。如果我不这样做,则docker run -d --name mms-c --mount命令返回:

9dd272dec48731982bebffa884a1a6eb81e211763b390eeb18f411781521d5a7
docker: Error response from daemon: container 9dd272dec48731982bebffa884a1a6eb81e211763b390eeb18f411781521d5a7 encountered an error during CreateProcess: failure in a Windows system call: The system can not find the stated file. (0x2)
[Event Detail:  Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail:  Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail: onecore\vm\compute\management\orchestration\vmhostedcontainer\processmanagement.cpp(173)\vmcomputeagent.exe!00007FF6157B9D2B: (caller: 00007FF61576E13A) Exception(4) tid(3a0) 80070002 The system cannot find the file specified.
    CallContext:[\Bridge_ProcessMessage\VmHostedContainer_ExecuteProcess]

标签: docker

解决方案


您是否尝试添加应用程序的名称?

像这样 :

docker run -d --name mms-c --mount type=bind,source="C:/Users/user/Desktop/ModellingMicroServices/mount/MicroServiceModelCompilerCore.exe",target="C:/app/Modeling/MicroServiceModelCompilerCore/bin/Debug/netcoreapp3.0/MicroServiceModelCompilerCore.exe" mms

推荐阅读