一些背景:我是了解Docker图像和容器以及如何编写Dockerfile的新手。我目前有一个Dockerfile,它可以通过PIP Install命令安装我想要的所有依赖项,因此,构建和部署图像非常简单。
但是我目前有一个新的要求使用DateInfer模块,并且无法通过PIP安装命令安装。
必须首先克隆仓库,然后必须安装,并且我很难通过Dockerfile实现这一目标。我现在一直关注的当前工作是运行容器并在目录中手动安装所有其他依赖项,并使用已安装的dateinfer进行更改。但是,这是一个非常繁琐且耗时的过程,我想通过在Dockerfile和我所有其他依赖项中提及它来实现同样的事情。
这就是我的dockerfile的样子:
FROM ubuntu:20.04
RUN apt update
RUN apt upgrade -y
RUN apt-get install -y python3
RUN apt-get install -y python3-pip
RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata
RUN apt-get install -y libenchant1c2a
RUN apt install git -y
RUN pip3 install argparse
RUN pip3 install boto3
RUN pip3 install numpy==1.19.1
RUN pip3 install scipy
RUN pip3 install pandas
RUN pip3 install scikit-learn
RUN pip3 install matplotlib
RUN pip3 install plotly
RUN pip3 install kaleido
RUN pip3 install fpdf
RUN pip3 install regex
RUN pip3 install pyenchant
RUN pip3 install openpyxl
ADD core.py /
ENTRYPOINT [ "/usr/bin/python3.8", "/core.py”]
因此,当我尝试像这样安装dateinfer时:
RUN git clone https://github.com/nedap/dateinfer.git
RUN cd dateinfer
RUN pip3 install .
它会引发以下错误:
错误:目录'。不可安装。尚未找到“ setup.py”和“ pyproject.toml”。
命令'/bin/sh -c pip3安装。返回一个非零代码:1
如何解决此问题?
Some background : I'm new to understanding docker images and containers and how to write DOCKERFILE. I currently have a Dockerfile which installs all the dependencies that I want through PIP install command and so, it was very simple to build and deploy images.
But I currently have a new requirement to use the Dateinfer module and that cannot be installed through the pip install command.
The repo has to be first cloned and then has to be installed and I'm having difficulty achieving this through a DOCKERFILE. The current work around I've been following for now is to run the container and install it manually in the directory with all the other dependencies and Committing the changes with dateinfer installed.But this is a very tedious and time consuming process and I want to achieve the same by just mentioning it in the DOCKERFILE along with all my other dependencies.
This is what my Dockerfile looks like:
FROM ubuntu:20.04
RUN apt update
RUN apt upgrade -y
RUN apt-get install -y python3
RUN apt-get install -y python3-pip
RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata
RUN apt-get install -y libenchant1c2a
RUN apt install git -y
RUN pip3 install argparse
RUN pip3 install boto3
RUN pip3 install numpy==1.19.1
RUN pip3 install scipy
RUN pip3 install pandas
RUN pip3 install scikit-learn
RUN pip3 install matplotlib
RUN pip3 install plotly
RUN pip3 install kaleido
RUN pip3 install fpdf
RUN pip3 install regex
RUN pip3 install pyenchant
RUN pip3 install openpyxl
ADD core.py /
ENTRYPOINT [ "/usr/bin/python3.8", "/core.py”]
So when I try to install Dateinfer like this:
RUN git clone https://github.com/nedap/dateinfer.git
RUN cd dateinfer
RUN pip3 install .
It throws the following error :
ERROR: Directory '.' is not installable. Neither 'setup.py' nor 'pyproject.toml' found.
The command '/bin/sh -c pip3 install .' returned a non-zero code: 1
How do I solve this?
发布评论
评论(1)
每个
运行
dockerfile
在其自己的子壳中运行。如果您写下这样的东西:那是一个毫无疑问的:它启动一个新的外壳,更改目录,然后壳退出。下一个
运行
命令执行时,您又回到了/
目录中。解决此问题的最简单方法是将您的命令包括在单个
运行
语句中:实际上,您还可以使用其他
pip install install
命令从中受益;而不是一堆个人运行
命令,请考虑:
这通常会更快,因为
pip
只需要解决依赖性一次。
而不是在命令上单独指定所有软件包
行,您也可以将它们放入
sumplions.txt
文件中,然后使用
PIP install -r Euncess.txt
。Each
RUN
directive in aDockerfile
runs in its own subshell. If you write something like this:That is a no-op: it starts a new shell, changes directory, and then the shell exits. When the next
RUN
command executes, you're back in the/
directory.The easiest way of resolving this is to include your commands in a single
RUN
statement:In fact, you would benefit from doing this with your other
pip install
commands as well; rather than a bunch of individualRUN
commands, consider instead:
That will generally be faster because
pip
only needs to resolvedependencies once.
Rather than specifying all the packages individually on the command
line, you could also put them into a
requirements.txt
file, and thenuse
pip install -r requirements.txt
.