【发布时间】:2020-09-01 00:42:24
【问题描述】:
我在尝试运行 Docker 映像时遇到了奇怪的情况
图像因找不到 dotnet 而失败,因此我连接到它以手动运行命令并查看发生了什么。
我的结构是:
- 码头工人:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
RUN apt-get update && apt-get -y install python3-pip
WORKDIR /app
COPY requirements.txt .
COPY publish .
COPY IRT .
COPY start.sh .
RUN chmod u+x ./start.sh
RUN pip3 install -r requirements.txt
ENTRYPOINT ["sh", "start.sh"]
- start.sh(为显示问题而简化)
timeout 15s ping google.com | grep -m 1 "icmp_seq=6" && dotnet Gatekeeper.dll
问题
如果我运行 sh start.sh,这是输出:
root@c53ecc22b25f:/app# sh start.sh
: not found: start.sh:
64 bytes from 216.58.211.110 (216.58.211.110): icmp_seq=6 ttl=37 time=15.9 ms
It was not possible to find any installed .NET Core SDKs
Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
https://aka.ms/dotnet-download
但是,如果我在不调用 start.sh 的情况下运行命令本身,它会完美运行:
root@c53ecc22b25f:/app# timeout 15s ping google.com | grep -m 1 "icmp_seq=6" && dotnet Gatekeeper.dll
64 bytes from 172.217.17.78 (172.217.17.78): icmp_seq=6 ttl=37 time=23.1 ms
info: AWSSDK[0]
Found AWS options in IConfiguration
info: AWSSDK[0]
Found credentials using the AWS SDK's default credential search
...
我已经尝试使用 dotnet 的完整路径 (/usr/bin/dotnet),但还是不行。
还有一些很奇怪的东西。如果我将 start.sh 修改为只有 dotnet Gatekeeper.dll,它可以工作。
我对 linux sh 不是很有经验,也不知道为什么会这样。 你能帮帮我吗?
额外: 为什么我需要这个命令?
- 我为入口点运行 2 个服务器,一个 python 服务器需要在 Dotnet 启动之前准备好,否则我的容器上会出现一种“冷启动”错误。
- 我已经有一个解决方法,我修改 c# 代码以继续尝试连接几秒钟,然后继续启动,但这并不理想,原因有几个。
【问题讨论】:
-
请以
./start.sh从当前目录运行start.sh文件并添加shebang行如#!/bin/sh or #!/bin/bash并设置可执行文件chmod 775 start.sh or chmod +x start.sh -
#!/bin/bash 已经存在,并且我作为 dockerfile 指令的一部分运行的 chmod 部分:(
-
这个问题不一样,start.sh执行了,"ping | grep"部分也执行了,dotnet不识别
-
我发现我的 start.sh 文件是用 EOF CRLF 保存的,更改为 LF 它在 | 之后成功执行了 dotnet 部分grep,我正在用 LF 文件构建一个新图像,希望这是问题所在(奇怪)