Linux 在SH文件中运行时未找到命令

Linux 在SH文件中运行时未找到命令,linux,bash,shell,docker,Linux,Bash,Shell,Docker,我在一个奇怪的情况下试图运行一个码头工人形象 该图像由于找不到dotnet而失败,因此我连接到它以手动运行命令并查看发生了什么 我的结构是: 码头工人: start.sh(简化以显示问题) 超时15秒ping google.com | grep-m1“icmp_seq=6”&&dotnet Gatekeeper.dll 问题 如果运行sh start.sh,这是输出: root@c53ecc22b25f:/app# sh start.sh : not found: start.sh:

我在一个奇怪的情况下试图运行一个码头工人形象

该图像由于找不到dotnet而失败,因此我连接到它以手动运行命令并查看发生了什么

我的结构是:

  • 码头工人:
  • start.sh(简化以显示问题)
超时15秒ping google.com | grep-m1“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,它会工作

我对LinuxSH不是很有经验,也不知道为什么会发生这种情况。 你能帮我吗

额外: 为什么我需要这个命令

  • 我为entrypoint运行了两台服务器,这是一台python服务器,需要在Dotnet启动之前准备就绪,否则我的容器上会出现某种“冷启动”错误
  • 我已经有了一个变通办法,修改c#代码,使其在几秒钟内继续尝试连接,然后继续启动,但这并不理想,原因有几个

请从当前目录以
/start.sh
的形式运行start.sh文件,并添加类似
#的shebang行/垃圾箱/垃圾箱或#/bin/bash
并设置可执行文件
chmod 775 start.sh或chmod+x start.sh
检查此url#/bin/bash已经存在,chmod part I作为dockerfile指令的一部分运行:(这个问题不同,start.sh被执行,“ping | grep”部分也被执行,dotnet不被识别。我发现我的start.sh文件是用EOF CRLF保存的,并更改为LF。它成功地执行了dotnet部分。在| grep之后,我正在用LF文件构建一个新图像,希望这就是问题所在(奇怪)
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
...