python 2.7でサブプロセスを呼び出そうとしています。このサブプロセスは、JAVA jarファイルを実行し、出力を読み取ります。私はドッカーコンテナでdjangoを使用しています。dockerコンテナでpythonサブプロセスを呼び出すときにエラーが発生しました
私は、関数を呼び出しています:
ここ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つのファイルがあります。私のローカルマシン上で実行可能ファイルを実行すると、同じ引数が私に結果を与えますが、これはしません。何が起きているのか?
EDIT
瓶が整備されているが、サブプロセスの呼び出しは失敗します。ローカルでは、正常に動作しています。経験豊富な専門家からのコメントで、私はドッカーファイルを見て、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/
マイ修正ドッカファイルは次のとおりです:
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"]
T
は、私は私の本発明の容器にJAVAをインストールするには、次のソースを読んで彼は失敗する。私はドッカーの知識が非常に限られています。私はそれを初めて知っています。誰かが問題を理解するのを助けたら、私は感謝しています。
Dockerファイルを共有してください –
jarファイルが手動で存在するかどうかを確認できます。 'docker exec -it bash'を実行し、pythonスクリプトのようなコマンドを実行しようとする –