Install.sh Cannot Be Found

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

Note that the error is giving you a line number, 1:. You’re running into using Windows line endings (\r\n) in a Unix container. So, either save the file using Unix line endings (\n), or use something like RUN dos2unix /install.sh (if adding that to your Ubuntu image first), or RUN perl -pi -e 's/\r\n|\n|\r/\n/g' /install.sh.

Aside, I wonder what CMD ["/bin/zsh"] is supposed to do.

Your solution to save using Unix line endings worked for me. In Visual Studio Code, you need to change the button on the bottom from “CRLF” to “LF”.

CMD ["/bin/zsh"] is supposed to prompt me with a zshell prompt when I start the container.

And does that work? Sounds like a Dockerfile CMD, not something that would work in a shell script executed by /bin/sh. But maybe the Docker magic somehow propagates into your script? :thinking:

Ok, here is everything I did that is working:

Step 1: Make a Dockerfile:

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

Step 2: make an install.sh file and save with Unix newlines:

#!/bin/bash

apt-get update  
apt-get upgrade -y  
apt-get install -y bzip2 gcc git iputils-ping htop screen vim wget zsh  
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 -)"

Step 3: Put the 2 files in your working directory
Step 4: In working directory, run:

docker volume create myvolume

Step 5, run:

docker build -t myapp:v1 .

Step 6, run:

docker run --mount type=volume,source=myvolume,dst=/mnt/storage -w /mnt/storage --network host -ti myapp:v1 zsh

At this point you will have a zsh prompt to your Docker container, and a container name will be automatically generated. If you keep running docker run commands, duplicate containers will get created with different container names. I only discovered this while using the docker desktop app for windows…

Step 7, exit the container:
exit
Step 8, start using the container again:

docker start -ai $auto_assigned_containername

Step 9, stop using container:
exit

Rinse and repeat…

Let me know if there is a more efficient way to do any of this.

You actually used the line which makes zsh the default command in your container but as @avbentem mentioned that was in the wrong file. You should have used that in your Dockerfile.

CMD ["/bin/zsh"] 

This is normal but if you read the documentation you will find the parameter --rm for docker run which deletes the container after it stopped and --name to use a custom name instead of randomly generated.

The above line in the shell script is uneccessary. You have already set the variable in your Dockerfile.