![](/img/trans.png)
[英]Substitute variables value in myscript.sh file when running with sh command
[英]Command not found when running inside a SH file
我在一个奇怪的情况下试图运行 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"]
timeout 15s ping google.com | grep -m 1 "icmp_seq=6" && dotnet Gatekeeper.dll
问题
如果我运行 sh start.sh,这是 output:
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 不是很有经验,也不知道为什么会这样。 你能帮助我吗?
额外:为什么我需要这个命令?
我认为脚本与 start.sh 的相关性尚未确定。 在脚本中,如果您使用绝对路径调用 start.sh,它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.