1

I'm attempting to run a Python file from a Docker container but receive the error:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"./models/PriceNotifications.py\": stat ./models/PriceNotifications.py: no such file or directory": unknown.

I build and run using commands:

docker build -t pythonstuff .

docker tag pythonstuff adr/test

docker run -t adr/test

Dockerfile:

FROM ubuntu:16.04

COPY . /models

# 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

CMD ["./models/PriceNotifications.py"]

install.sh:

apt-get update  # updates the package index cache
apt-get upgrade -y  # updates packages
# installs system tools
apt-get install -y bzip2 gcc git  # system tools
apt-get install -y htop screen vim wget  # system tools
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.anaconda.com/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 install -y pandas  # installs pandas
conda install -y ipython  # installs IPython shell

# CUSTOMIZATION
cd /root/
wget http://hilpisch.com/.vimrc  # Vim configuration

I've tried modifying the CMD within the Dockerfile to :

CMD ["/models/PriceNotifications.py"]

but the same error occurs.

The file structure is as follows:

enter image description here

How should I modify the Dockerfile or dir structure so that models/PriceNotifications.py is found and executed ?

blue-sky
  • 45,835
  • 124
  • 360
  • 647
  • 1
    To debug this you might run your container like this: docker run -it --entrypoint /bin/bash adr/test This opens a bash shell which can be used to find the correct path. – Chris Dec 23 '20 at 10:20
  • Does `COPY . /models` maybe copy local "./models" to `/models/models/` on the VM? Maybe `COPY ./models /models` would do it. – C14L Dec 23 '20 at 10:46
  • 2
    What is the very first line of the `PriceNotifications.py` script? Is it executable? – David Maze Dec 23 '20 at 11:04
  • @DavidMaze the first line of PriceNotifications.py is an import: 'import time' – blue-sky Dec 23 '20 at 12:47
  • 1
    It should probably [begin with](https://stackoverflow.com/questions/2429511/why-do-people-write-usr-bin-env-python-on-the-first-line-of-a-python-script) `#!/usr/bin/env python3`, which will tell the system how to run it as a standalone script. – David Maze Dec 23 '20 at 13:01

1 Answers1

0

Thanks to earlier comments, using the path:

CMD ["/models/models/PriceNotifications.py"]

instead of

CMD ["./models/PriceNotifications.py"]

Allows the Python script to run.

I would have thought CMD ["python /models/models/PriceNotifications.py"] should be used instead of CMD ["/models/models/PriceNotifications.py"] to invoke the Python interpreter but the interpreter seems to be already available as part of the Docker run.

blue-sky
  • 45,835
  • 124
  • 360
  • 647