Docker Can't Find Install.sh

Viewed 422

I created a folder in Windows that has a Dockerfile and an install.sh script. When I attempt to build the docker image, I get an error that says:

 => ERROR [4/4] RUN /install.sh                                                                                                                        0.6s
------
 > [4/4] RUN /install.sh:
#7 0.584 /bin/sh: 1: /install.sh: not found

This is my Dockerfile:

FROM ubuntu:latest  
ADD install.sh /
RUN chmod u+x /install.sh
RUN /install.sh
ENV PATH /root/miniconda3/bin:$PATH

This is my install.sh:

#!/bin/bash

apt-get update  
apt-get upgrade -y  
apt-get install -y bzip2 gcc git ping htop screen vim wget  
apt-get clean  

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O Miniconda.sh
bash Miniconda.sh -b  
rm -rf Miniconda.sh  
export PATH="/root/miniconda3/bin:$PATH"  

conda install -y pandas  
sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

CMD ["/bin/zsh"]

This is what I am running in Windows to produce the error:

docker build -t app_test:v1.01 .

output:

[+] Building 1.3s (8/8) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                   0.0s
 => => transferring dockerfile: 158B                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                        0.0s
 => [internal] load metadata for docker.io/library/ubuntu:latest                                                                                       0.0s
 => [internal] load build context                                                                                                                      0.0s
 => => transferring context: 490B                                                                                                                      0.0s
 => CACHED [1/4] FROM docker.io/library/ubuntu:latest                                                                                                  0.0s
 => [2/4] ADD install.sh /                                                                                                                             0.0s
 => [3/4] RUN chmod u+x /install.sh                                                                                                                    0.5s
 => ERROR [4/4] RUN /install.sh                                                                                                                        0.6s
------
 > [4/4] RUN /install.sh:
#7 0.584 /bin/sh: 1: /install.sh: not found
------
executor failed running [/bin/sh -c /install.sh]: exit code: 127

So far I've tried the following:

  1. renaming the install.sh file to something else
  2. Changing the ADD line to COPY so that the line says COPY install.sh /install.sh
  3. googling the issue to see anyone else has experienced something similar.

EDIT #1:

tree and ls output:

PS C:\Users\Rick\Documents\experiments> tree
Folder PATH listing
Volume serial number is D49A-7235
C:.
No subfolders exist

PS C:\Users\Rick\Documents\experiments> ls

    Directory: C:\Users\Rick\Documents\experiments

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          11/21/2021 11:11 AM            132 Dockerfile
-a---          11/21/2021  9:05 AM            451 install.sh

EDIT #2 adding RUN ls / to Dockerfile:

[+] Building 2.0s (9/9) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                   0.0s
 => => transferring dockerfile: 181B                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                        0.0s
 => [internal] load metadata for docker.io/library/ubuntu:latest                                                                                       0.0s
 => [internal] load build context                                                                                                                      0.0s
 => => transferring context: 32B                                                                                                                       0.0s
 => [1/5] FROM docker.io/library/ubuntu:latest                                                                                                         0.0s
 => CACHED [2/5] COPY install.sh /install.sh                                                                                                           0.0s
 => [3/5] RUN ls /                                                                                                                                     0.5s
 => [4/5] RUN chmod u+x /install.sh                                                                                                                    0.6s
 => ERROR [5/5] RUN /install.sh                                                                                                                        0.7s
------
 > [5/5] RUN /install.sh:
#9 0.694 /bin/sh: 1: /install.sh: not found
------
executor failed running [/bin/sh -c /install.sh]: exit code: 127
1 Answers

The cause of the issue was saving the install.sh file using Windows line endings. It needed to be saved using Unix line endings. In Visual Studio Code, change the "CRLF" button to "LF".

Related