尝试运行pip时出现以下错误。
Could not open requirements file: [Errno 2] No such file or directory: '/home/elasticsearch/text-embeddings/requirements.txt'
The command '/bin/sh -c pip3.6 install -r /home/elasticsearch/text-embeddings/requirements.txt' returned a non-zero code: 1
我的dockerfile看起来像这样...
FROM elasticsearch:7.3.1
RUN yum install -y https://centos7.iuscommunity.org/ius-release.rpm
RUN yum update
RUN yum install -y python36u python36u-libs python36u-devel python36u-pip git
RUN mkdir /home/elasticsearch/
RUN cd /home/elasticsearch/
RUN git clone https://github.com/jtibshirani/text-embeddings.git
WORKDIR /home/elasticsearch/text-embeddings
RUN cd /home/elasticsearch/text-embeddings
RUN pip3.6 install -r /home/elasticsearch/text-embeddings/requirements.txt
CMD ["python3.6", "/home/elasticsearch/text-embeddings/src/main.py"]
如果从命令提示符处一次运行一个命令,我已经检查了这些命令是否可以在服务器上成功运行。
答案 0 :(得分:3)
尝试使用以下Dockerfile:
FROM elasticsearch:7.3.1
RUN yum install -y https://centos7.iuscommunity.org/ius-release.rpm
RUN yum update
RUN yum install -y python36u python36u-libs python36u-devel python36u-pip git
RUN mkdir /home/elasticsearch/
WORKDIR /home/elasticsearch/
RUN git clone https://github.com/jtibshirani/text-embeddings.git
RUN pip3.6 install -r /home/elasticsearch/text-embeddings/requirements.txt
CMD ["python3.6", "/home/elasticsearch/text-embeddings/src/main.py"]
原始Dockerfile的问题是RUN cd /path
。每个构建阶段都在单独的容器中执行,因此cd
进入目录不会执行任何操作。要在构建过程中更改活动目录,请使用WORKDIR
指令。
答案 1 :(得分:2)
文件requirements.txt
位于/usr/share/elasticsearch/text-embeddings
中,而不是/home/elasticsearch/text-embeddings
这将起作用:
FROM elasticsearch:7.3.1
RUN yum install -y https://centos7.iuscommunity.org/ius-release.rpm
RUN yum update
RUN yum install -y python36u python36u-libs python36u-devel python36u-pip git
RUN git clone https://github.com/jtibshirani/text-embeddings.git
WORKDIR /usr/share/elasticsearch/text-embeddings
RUN pip3.6 install -r /usr/share/elasticsearch/text-embeddings/requirements.txt
CMD ["python3.6", "/usr/share/elasticsearch/text-embeddings/src/main.py"]
答案 2 :(得分:2)
该问题是由于以下几个答案的结合而来的,@ leopal是正确的,而@SpringBootApplication
public class WebWalletApplication implements CommandLineRunner {
@Value("${server.port}")
private String serverPort;
@Value("${server.address}")
private String serverAddress;
public static void main(String[] args) {
SpringApplication.run(WebWalletApplication.class, args);
}
@Override
public void run(String... args) {
try {
openHomePage();
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
private void openHomePage() throws URISyntaxException {
System.out.println("serverAddress: " + serverAddress);
String url = "https://" + serverAddress + ":" + serverPort + "/wallet/secure/home";
URI homepage = new URI(url);
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(homepage);
} catch (IOException e) {
e.printStackTrace();
}
} else {
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("rundll32 url.dll,FileProtocolHandler " + url);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
和mkdir
在不同的层中运行,并不会导致您期望的结果参考this answer。
cd
...运行容器(即FROM elasticsearch:7.3.1
RUN yum install -y https://centos7.iuscommunity.org/ius-release.rpm
RUN yum update
RUN yum install -y python36u python36u-libs python36u-devel python36u-pip git
RUN mkdir /home/elasticsearch/
RUN cd /home/elasticsearch/
RUN git clone https://github.com/jtibshirani/text-embeddings.git
ENTRYPOINT ["bash"]
)会将您放入docker build -t so:57689606 . && docker run --rm -it so:57689606
目录中的shell中,其中包含@LinPy here指出的所有文件。在结帐后添加/usr/share/elasticsearch
会将您移动到未克隆存储库的目录(例如WORKDIR
)。
/home/elasticsearch
...将在运行容器时将您放入空文件夹内的外壳中(因此发生FROM elasticsearch:7.3.1
RUN yum install -y https://centos7.iuscommunity.org/ius-release.rpm
RUN yum update
RUN yum install -y python36u python36u-libs python36u-devel python36u-pip git
RUN mkdir /home/elasticsearch/
RUN cd /home/elasticsearch/
RUN git clone https://github.com/jtibshirani/text-embeddings.git
WORKDIR /home/elasticsearch/text-embeddings
ENTRYPOINT ["bash"]
错误)。
此外,指定[Errno 2] No such file or directory
会创建目录(如果尚不存在),例如您的WORKDIR
和RUN mkdir /home/elasticsearch/
指令无法正常工作,仅在最终图像中添加了无用的图层。功能性RUN cd /home/elasticsearch
:
Dockerfile
最后,删除最终图像中的不必要的图层(优化的FROM elasticsearch:7.3.1
RUN yum install -y https://centos7.iuscommunity.org/ius-release.rpm
RUN yum update
RUN yum install -y python36u python36u-libs python36u-devel python36u-pip git
WORKDIR /home/elasticsearch/
RUN git clone https://github.com/jtibshirani/text-embeddings.git
RUN python3.6 -m pip install -r /home/elasticsearch/text-embeddings/requirements.txt
CMD ["python3.6", "/home/elasticsearch/text-embeddings/src/main.py"]
):
Dockerfile
注意:FROM elasticsearch:7.3.1
RUN yum install -y https://centos7.iuscommunity.org/ius-release.rpm
RUN yum update && \
yum install -y \
python36u \
python36u-libs \
python36u-devel \
python36u-pip \
git && \
yum clean all
WORKDIR /home/elasticsearch/
RUN git clone https://github.com/jtibshirani/text-embeddings.git && \
python3.6 -m pip install -r /home/elasticsearch/text-embeddings/requirements.txt
ENTRYPOINT ["python3.6"]
CMD ["/home/elasticsearch/text-embeddings/src/main.py"]
程序包故意分成多行,因此可以一目了然地查看apt
imo中的变化。
答案 3 :(得分:0)
在Dockerfile中尝试此命令并尝试。
运行pip install --trusted-host pypi.python.org -r requirements.txt