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!!!
EDIT: this is the bash script I’m using:
#!/bin/bash
#
# Script to Install
# Linux System Tools and
# Basic Python Components
#
# Python for Finance, 2nd ed.
# (c) Dr. Yves J. Hilpisch
#
# GENERAL LINUX
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
# INSTALL MINICONDA
# downloads Miniconda
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O
Miniconda.sh
bash Miniconda.sh -b # installs it
rm -rf Miniconda.sh # removes the installer
export PATH="/root/miniconda3/bin:$PATH" # prepends the new path
# INSTALL PYTHON LIBRARIES
conda update -y conda python # updates conda & Python (if required)
conda install -y pandas # installs pandas
conda install -y ipython # installs IPython shell
2
Answers
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.
Mind sharing your
install.sh
script as well? I’ve tried reproducing on my laptop by using an emptyinstall.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 ofADD
, but i don’t think this is the problem here as it’s working for me.