1

I'm in a weird situation trying to run a Docker image

The image is failing for not finding the dotnet, so then I connected to it to run manually the commands and see what's going on.

My structure is:

  • Docker:
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 (simplified for show the problem)
timeout 15s ping google.com | grep -m 1 "icmp_seq=6" && dotnet Gatekeeper.dll

The Problem

If I run sh start.sh, this is the 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

BUT, If I run the command itself without calling the start.sh, it works perfectly:

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
...

I have already tried to use the full path for dotnet (/usr/bin/dotnet) but still it doesn't work.

Also something very weird. if I modify the start.sh to have only dotnet Gatekeeper.dll, it works.

I am not very experienced with linux sh and have no idea why this is happening. Can you help me ?

Extra: Why do I need this command?

  • I run 2 servers for the entrypoint, a python server that is required to be ready before the Dotnet start, otherwise I have a kind of "Cold start" error on my containers.
  • I have already a workaround where I modify the c# code to keep trying to connect to for some seconds and then proceed with the startup, but this is not ideal for several reasons.
Nicollas Braga
  • 802
  • 7
  • 27
  • Please run the start.sh file as `./start.sh` from current directory also add shebang line like `#!/bin/sh or #!/bin/bash` and also set executable `chmod 775 start.sh or chmod +x start.sh` – amit bhosale May 15 '20 at 09:01
  • check this url https://stackoverflow.com/questions/37419042/container-command-start-sh-not-found-or-does-not-exist-entrypoint-to-contain – amit bhosale May 15 '20 at 09:04
  • the #!/bin/bash is already there, and the chmod part I run as part of the dockerfile instructions :( – Nicollas Braga May 15 '20 at 09:07
  • this problem is different, the start.sh is executed, the "ping | grep" part is also executed, the dotnet is not recognized – Nicollas Braga May 15 '20 at 09:09
  • Please chek this url https://stackoverflow.com/questions/51540552/how-can-i-have-a-shell-script-point-to-a-dll-docker-entrypoint .. `ENTRYPOINT ["/start.sh"]` – amit bhosale May 15 '20 at 09:13
  • also use `docker run --entrypoint /bin/bash -it [image]` or `docker run -it --entrypoint="/bin/sh" my_image` – amit bhosale May 15 '20 at 09:19
  • 1
    I found out that my start.sh file was saved with EOF CRLF, and changing to LF it successfully executed the dotnet part after the | grep, I'm building a new image with LF files, hope this was the problem ( bizarre ) – Nicollas Braga May 15 '20 at 10:12

1 Answers1

-1

I think the relativeness of the script to start.sh is not well established. In the script if you callout start.sh using absolute path it should work.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30699587) – Mad Physicist Jan 02 '22 at 02:57