简体   繁体   English

Docker“运行”找不到文件

[英]Docker 'run' not finding file

I'm attempting to run a Python file from a Docker container but receive the error:我正在尝试从 Docker 容器运行 Python 文件,但收到错误:

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: 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:安装.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:我尝试将 Dockerfile 中的 CMD 修改为:

CMD ["/models/PriceNotifications.py"]

but the same error occurs.但同样的错误发生。

The file structure is as follows:文件结构如下:

在此处输入图像描述

How should I modify the Dockerfile or dir structure so that models/PriceNotifications.py is found and executed?我应该如何修改 Dockerfile 或 dir 结构,以便找到并执行models/PriceNotifications.py

Thanks to earlier comments, using the path:感谢之前的评论,使用路径:

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

instead of代替

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

Allows the Python script to run.允许 Python 脚本运行。

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. 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 Docker 运行的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM