Why isn't docker build running my bash script?


I’m trying to create a Docker image using a Dockerfile and a bash script, but I keep getting this error:

(base) [email protected]:~/Docker$ docker build -t py4fi:basic .
[+] Building 0.5s (8/8) FINISHED
 => [internal] load build definition from Dockerfile                                                            0.0s
 => => transferring dockerfile: 38B                                                                             0.0s
 => [internal] load .dockerignore                                                                               0.1s
 => => 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/4] FROM docker.io/library/ubuntu:latest                                                                  0.0s
 => CACHED [2/4] ADD install.sh /                                                                               0.0s
 => CACHED [3/4] RUN chmod u+x /install.sh                                                                      0.0s
 => ERROR [4/4] RUN /install.sh                                                                                 0.4s
 > [4/4] RUN /install.sh:
#7 0.326 /bin/sh: 1: /install.sh: not found
executor failed running [/bin/sh -c /install.sh]: exit code: 127

I understand it is because the install.sh file isn’t found, but I don’t know why. My directory "Docker" contains:

(base) [email protected]:~/Docker$ ls
Dockerfile  install.sh

My Dockerfile looks like this:

# Building a Docker Image with
# the Latest Ubuntu Version and
# Basic Python Install
# Python for Finance, 2nd ed.
# (c) Dr. Yves J. Hilpisch

# latest Ubuntu version
FROM ubuntu:latest

# information about maintainer

# add the bash script
ADD install.sh /

# change rights for the script
RUN chmod u+x /install.sh

# run the bash script
RUN /install.sh

# prepend the new path
ENV PATH /root/miniconda3/bin:$PATH

# execute IPython when container is run
CMD ["ipython"]

Thanks in advance!!!

EDIT: this is the bash script I’m using:

# Script to Install
# Linux System Tools and
# Basic Python Components
# Python for Finance, 2nd ed.
# (c) Dr. Yves J. Hilpisch
apt-get update  # updates the package index cache
apt-get upgrade -y  # updates packages
# installs system tools
apt-get install -y bzip2 gcc git htop screen vim wget
apt-get upgrade -y bash  # upgrades bash if necessary
apt-get clean  # cleans up the package index cache

# downloads Miniconda
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O \
bash Miniconda.sh -b  # installs it
rm -rf Miniconda.sh  # removes the installer
export PATH="/root/miniconda3/bin:$PATH"  # prepends the new path

conda update -y conda python # updates conda & Python (if required)
conda install -y pandas  # installs pandas
conda install -y ipython  # installs IPython shell


If you’ve edited your .sh file in Windows it could have encoded the file with CR-LF line endings.

Please open the shell script in Notepad++ then edit —> EOL Conversion —> UNIX/OSX Format.

Then please try and build/run your Dockerfile again.

Answered By – JasonS

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published