我正在尝试在python 2.7中调用子进程。此子进程执行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已就绪,但子进程调用失败。在当地,它运行良好。有经验的专业人士的评论,我看了一下docker文件,我意识到容器内缺少Java。我尝试在此容器上安装Java但构建失败。
我阅读了以下来源,在我目前的容器上安装JAVA:
Best way to install java 8 using docker?
https://www.ivankrizsan.se/2015/08/08/creating-a-docker-image-with-ubuntu-and-java/
我修改过的docker文件是:
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"]
构建失败。我对码头工人的了解非常有限,因为我是新手,如果有人帮助我找出问题,我将不胜感激。
答案 0 :(得分:0)
好的,我明白了。我正在使用python 2.7的基本映像我将其更改为ubuntu并安装了我想要使用的Java,Python和Ruby。