2

I have a feeling this has something to do with the fact I am running docker for windows. Maybe something to do with the formatting of files in windows vs Linux...

I just had weirdest thing happen to my Docker. Docker images that I build using the command DOCKER BUILD are now erroring when I run them as a container saying that the files that in the ENTRYPOINT cannot be found.

[FATAL tini (7)] exec /bin/start_vsftpd.sh failed: No such file or directory 

These images are not MINE, they are GIT repos from GITHUB which 100% work and I have ran them several times in the past without issue (as i expect you to assume I have done something wrong here). However, yesterday I made some changes to the docker file and rebuilt them. It worked fine. Today for some reason it stopped working. So I rolled them all back to how they were before. This still did not resolve the issue. And here is the strangest part - in the end I just wiped everything - the repo from machine, all images and containers, and started fresh. I downloaded the repo again (which hasn't been updated in 10 months) and I have the same issue where when running the container it cannot find said file.

Some more info - the docker file itself uses the COPY command to copy an sh file from my local machine (the repo) into the image, this DOES work. I know this because I managed to connect to the running container and can see the file where it should be.

I can't think of anything I have changed on my machine. Can anyone advise what might be going on here? enter image description here Docker file below. It is the /bin/start_vsftpd.sh it says it cannot find.

ARG BASE_IMG=alpine:3.15

FROM $BASE_IMG AS pidproxy

RUN apk --no-cache add alpine-sdk \
 && git clone https://github.com/ZentriaMC/pidproxy.git \
 && cd pidproxy \
 && git checkout 193e5080e3e9b733a59e25d8f7ec84aee374b9bb \
 && sed -i 's/-mtune=generic/-mtune=native/g' Makefile \
 && make \
 && mv pidproxy /usr/bin/pidproxy \
 && cd .. \
 && rm -rf pidproxy \
 && apk del alpine-sdk


FROM $BASE_IMG

COPY --from=pidproxy /usr/bin/pidproxy /usr/bin/pidproxy
RUN apk --no-cache add vsftpd tini

COPY start_vsftpd.sh /bin/start_vsftpd.sh
COPY vsftpd.conf /etc/vsftpd/vsftpd.conf

EXPOSE 21 21000-21010
VOLUME /ftp/ftp

ENTRYPOINT ["/sbin/tini", "--", "/bin/start_vsftpd.sh"]
Mucker
  • 257
  • 3
  • 12
  • what's the exact error message? – erik258 Apr 23 '23 at 13:35
  • [FATAL tini (7)] exec /bin/start_vsftpd.sh failed: No such file or directory – Mucker Apr 23 '23 at 13:37
  • if I google for similar issues, the general consenus is that the file is for a different architecture. This is why I think it might be related to windows, like Docker sees it as a windows file and doesn't convert it to linux. Something like that – Mucker Apr 23 '23 at 13:38
  • shell scripts don't have an architecture they're just text. Though windows is quirky so I can't speak to that. What does the shebang line of the shell script look like and does the program it invokes exist? – erik258 Apr 23 '23 at 13:42
  • Sorry, I am a linux noob, don't know what you mean there. – Mucker Apr 23 '23 at 13:43
  • top of the shell script starts with `#!`? That's a shebang line and tells the computer how to execute the file . – erik258 Apr 23 '23 at 13:43
  • here it is: #!/bin/sh – Mucker Apr 23 '23 at 13:44
  • 2
    Make sure the file is not saved with windows linefeeds. `/bn/sh` may exist, but `/bin/sh\r` does not. – BMitch Apr 23 '23 at 14:46
  • Possible duplicate: https://stackoverflow.com/a/51770305/596285 – BMitch Apr 23 '23 at 14:49
  • @Mitch, I assume your comment about windows linefeeds doesn't matter if I am running the commands directly in the container? (See new screenshot I've added above) – Mucker Apr 24 '23 at 00:02

2 Answers2

3

I found the cause of this, and it was indeed due to Windows!

Oddly, if you get a copy of a repo from GITHUB via the zip file method, then extract it, it keeps the correct Linux line feeds intact. If, however, you use the clone GIT repo method in Visual Studio code, it seems to create the files with windows line feeds.

When Docker build runs, it copies the .sh file using windows line feeds and this is the cause of the image (and I assume any Linux OS) not being able to seee the .sh file.

To fix this, before building the image you need to edit the .sh file and convert the line feed to LF rather than what Windows selects as the default - CRLF. This shoulf fix the issue, however, I would also advise changing this for all files. I believe there is an option in Visual Studio code to turn this on for all files (just google it).

enter image description here

Mucker
  • 257
  • 3
  • 12
  • This behavior can be controlled by git configuration https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings – erik258 Aug 10 '23 at 13:42
0

Mucker's answer helped me (thank you!), adding this as an answer instead of a comment because comments do not allow images.

Just wanted to add that notepad++ has a convenient converter to quickly and easily change all those line endings:

enter image description here

wallismark
  • 1,766
  • 2
  • 21
  • 35