Home > other >  Why isn't docker build running my bash script?
Why isn't docker build running my bash script?

Time:08-02

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

(base) mmedina@LAPTOP-OBHFL78T:~/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) mmedina@LAPTOP-OBHFL78T:~/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
MAINTAINER yves

# 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!!!

CodePudding user response:

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.

CodePudding user response:

Mind sharing your install.sh script as well? I've tried reproducing on my laptop by using an empty install.sh file and the build succeeds hence i'm suspecting something into your bash script.

Although as per general best prctices, it is adviced to use COPY instead of ADD, but i don't think this is the problem here as it's working for me.

  • Related