如何在docker容器中为CLI预先添加内容?

如何在docker容器中为CLI预先添加内容?,docker,mono,dockerfile,Docker,Mono,Dockerfile,我想在传入docker容器的CLI中预先添加一些内容 我希望它像这样运行: FROM centeredge/nuget ARG VERSION="14.1.0.0-prerelease" RUN nuget install Microsoft.Build.Mono.Debug -Version $VERSION -Source "https://www.myget.org/F/dotnet-buildtools/" ENV PATH="/Microsoft.Build.Mono.Debug.$V

我想在传入docker容器的CLI中预先添加一些内容

我希望它像这样运行:

FROM centeredge/nuget
ARG VERSION="14.1.0.0-prerelease"
RUN nuget install Microsoft.Build.Mono.Debug -Version $VERSION -Source "https://www.myget.org/F/dotnet-buildtools/"
ENV PATH="/Microsoft.Build.Mono.Debug.$VERSION/lib/:${PATH}"
COPY entrypoint.sh /usr/src/
RUN chmod a+x /usr/src/entrypoint.sh
ENTRYPOINT ["/usr/src/entrypoint.sh"]
docker运行-it mstools msbuild.exe-版本

但是,为了在内部工作,我需要在msbuild.exe和mono之间预先设置完整路径,如下所示:

FROM centeredge/nuget
ARG VERSION="14.1.0.0-prerelease"
RUN nuget install Microsoft.Build.Mono.Debug -Version $VERSION -Source "https://www.myget.org/F/dotnet-buildtools/"
ENV PATH="/Microsoft.Build.Mono.Debug.$VERSION/lib/:${PATH}"
COPY entrypoint.sh /usr/src/
RUN chmod a+x /usr/src/entrypoint.sh
ENTRYPOINT ["/usr/src/entrypoint.sh"]
mono/Microsoft.Build.mono.Debug.14.1.0.0-prerelease/lib/msbuild.exe-版本

当我将下面的Dockerfile与命令一起使用时,我得到以下结果:

$ docker run -it mstools msbuild.exe --version
msbuild.exe: 1: msbuild.exe: [/usr/bin/mono,: not found
如果我跳入容器并检查路径:

$ docker run -it --entrypoint=bash mstools
root@eb47008f092e:/# which mono
/usr/bin/mono
我错过了什么

Dockerfile:

FROM centeredge/nuget
ARG VERSION="14.1.0.0-prerelease"
RUN nuget install Microsoft.Build.Mono.Debug -Version $VERSION -Source "https://www.myget.org/F/dotnet-buildtools/"
ENV PATH="/Microsoft.Build.Mono.Debug.$VERSION/lib/:${PATH}"
ENTRYPOINT ['/usr/bin/mono', " /Microsoft.Build.Mono.Debug.$VERSION/lib/$1 $@"]

您得到的错误肯定是因为您在entrypointexec表单中使用了单引号而不是双引号

此外,我认为您提到的$@语法不起作用,因为$@需要一些shell来计算它,而在exec表单中没有/bin/sh-c…隐含。但是ENTRYPOINT的exec形式肯定是一条路要走

所以我建议你写这样的东西:

FROM centeredge/nuget
ARG VERSION="14.1.0.0-prerelease"
RUN nuget install Microsoft.Build.Mono.Debug -Version $VERSION -Source "https://www.myget.org/F/dotnet-buildtools/"
ENV PATH="/Microsoft.Build.Mono.Debug.$VERSION/lib/:${PATH}"
COPY entrypoint.sh /usr/src/
RUN chmod a+x /usr/src/entrypoint.sh
ENTRYPOINT ["/usr/src/entrypoint.sh"]
entrypoint.sh包含:

#!/bin/bash
exec /usr/bin/mono "/Microsoft.Build.Mono.Debug.$VERSION/lib/$1" "$@"

注意:我现在还没有测试这个示例代码,所以如果您发现一些打字错误,请根据@ErikMD的答案发表评论:

FROM centeredge/nuget
ARG VERSION="14.1.0.0-prerelease"
RUN nuget install Microsoft.Build.Mono.Debug -Version $VERSION -Source "https://www.myget.org/F/dotnet-buildtools/"
ENV PATH="/Microsoft.Build.Mono.Debug.$VERSION/lib/:/Microsoft.Build.Mono.Debug.$VERSION/lib/tools/:${PATH}"
RUN echo '#!/bin/bash' > /usr/src/entrypoint.sh && echo 'exec /usr/bin/mono "$(which "$1")" "$@"' >> /usr/src/entrypoint.sh && chmod a+x /usr/src/entrypoint.sh
ENTRYPOINT ["/usr/src/entrypoint.sh"]
输出

 docker run -it mstools MSBuild.exe -version
Microsoft (R) Build Engine version 14.1.0.0
Copyright (C) Microsoft Corporation. All rights reserved.

14.1.0.0

如果可以的话,我不想在构建中添加一个单独的文件,所以我内联了为入口点创建的文件-我怀疑这是必要的。你获奖了。我将发布最终解决方案很高兴建议的解决方案对您有效:但是请注意,还有一个报价问题$1和$@应该始终用双引号括起来,您可能应该合并两个RUN命令。因此建议使用以下代码:运行echo'/bin/bash'>/usr/src/entrypoint.sh&&echo'exec/usr/bin/mono/Microsoft.Build.mono.Debug.$VERSION/lib/$1$@'>/usr/src/entrypoint.sh&&chmod a+x/usr/src/entrypoint.shFYI我已经按照建议编辑了您的答案− 添加缺少的引号并合并两个RUN命令以减少层的数量。如果需要,可以自由地作出反应或进一步编辑