在docker容器中调用pythonsubprocess时出错

我想在Python 2.7中调用一个subprocess。 这个subprocess执行一个JAVA jar文件并读取输出。 我在docker集装箱中使用Django。

我正在调用一个函数:

def call_exec(lang) curdir = curdir = 'ht/exec_folder' tmp_files_dir = 'ht/temp_files' script_args = ["java","-jar",'/'+curdir + "/executable.jar", "-l",lang,"-s",'/'+tmp_files_dir] output = subprocess.check_output(script_args) return output 

这里,ht是我的Django应用程序中的一个文件夹。 我正在尝试使用executable.jar并读取输出。 其他参数是为了运行可执行文件。 以下是产生的错误:

 django_1 | similarity = call_exec('english') django_1 | File "/app/langswipe/submissions/check_view.py", line 80, in call_exec django_1 | output = subprocess.check_output(script_args) django_1 | File "/usr/local/lib/python2.7/subprocess.py", line 567, in check_output django_1 | process = Popen(stdout=PIPE, *popenargs, **kwargs) django_1 | File "/usr/local/lib/python2.7/subprocess.py", line 711, in __init__ django_1 | errread, errwrite) django_1 | File "/usr/local/lib/python2.7/subprocess.py", line 1343, in _execute_child django_1 | raise child_exception django_1 | OSError: [Errno 2] No such file or directory 

tmp_files_dir中有2个文件。 当我在本地机器上运行可执行文件时,相同的参数给了我一个结果,但是这个不是。 任何线索发生了什么?

编辑

jar已经存在,但subprocess调用失败。 本地,它运行良好。 随着经验丰富的专业人士的意见,我看了一下docker文件,我意识到Java在容器内丢失。 我试图在这个容器上安装Java,但是构build失败。

我阅读以下来源,以在我的当前容器上安装JAVA:

使用docker安装java 8的最佳方法是什么?

Creating a Docker Image with Ubuntu and Java

https://raw.githubusercontent.com/docker-library/openjdk/e6e9cf8b21516ba764189916d35be57486203c95/8-jdk/Dockerfile

我修改的泊坞窗文件是:

 FROM python:2.7 ENV PYTHONUNBUFFERED 1 # to accomodate slate RUN easy_install distribute # Requirements have to be pulled and installed here, otherwise caching won't work COPY ./requirements /requirements RUN pip install -r /requirements/production.txt && \ mkdir -p /usr/share/nltk_data && \ python -m nltk.downloader -d /usr/share/nltk_data punkt stopwords wordnet averaged_perceptron_tagger && \ apt-get update && apt-get install poppler-utils -qy RUN groupadd -r django && useradd -r -g django django COPY . /app RUN chown -R django /app COPY ./compose/django/gunicorn.sh /gunicorn.sh COPY ./compose/django/entrypoint.sh /entrypoint.sh RUN sed -i 's/\r//' /entrypoint.sh RUN sed -i 's/\r//' /gunicorn.sh RUN chmod +x /entrypoint.sh && chown django /entrypoint.sh RUN chmod +x /gunicorn.sh && chown django /gunicorn.sh RUN apt-get update && apt-get install -y --no-install-recommends \ bzip2 \ unzip \ xz-utils \ && rm -rf /var/lib/apt/lists/* RUN echo 'deb http://deb.debian.org/debian jessie-backports main' > /etc/apt/sources.list.d/jessie-backports.list # Default to UTF-8 file.encoding ENV LANG C.UTF-8 # add a simple script that can auto-detect the appropriate JAVA_HOME value # based on whether the JDK or only the JRE is installed RUN { \ echo '#!/bin/sh'; \ echo 'set -e'; \ echo; \ echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \ } > /usr/local/bin/docker-java-home \ && chmod +x /usr/local/bin/docker-java-home ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64 ENV JAVA_VERSION 8u111 ENV JAVA_DEBIAN_VERSION 8u111-b14-2~bpo8+1 # see https://bugs.debian.org/775775 # and https://github.com/docker-library/java/issues/19#issuecomment-70546872 ENV CA_CERTIFICATES_JAVA_VERSION 20140324 RUN set -x \ && apt-get update \ && apt-get install -y \ openjdk-8-jdk="$JAVA_DEBIAN_VERSION" \ ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" \ && rm -rf /var/lib/apt/lists/* \ && [ "$JAVA_HOME" = "$(docker-java-home)" ] # see CA_CERTIFICATES_JAVA_VERSION notes above RUN /var/lib/dpkg/info/ca-certificates-java.postinst configure WORKDIR /app ENTRYPOINT ["/entrypoint.sh"] 

构build失败。 我对docker的知识非常有限,因为我是新手,如果有人帮我解决问题,我将不胜感激。

好吧,所以我明白了。 我使用的是python 2.7的基础映像,我将其改为Ubuntu,并安装了我想使用的Java,Python和Ruby。