1

i am new to docker and trying to dockerize a java app, which in turn calls a python script

Dockerfile :

FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
ARG SCRIPT_FILE=src/main/resources/script/test.py

COPY ${JAR_FILE} app.jar
COPY ${SCRIPT_FILE} test.py
ENTRYPOINT ["java","-jar","/app.jar"]

Now my App has a line of code which executes a python script, something like this : Code snippet :

        String interpretor = "python";
        String scriptFile = "test.py";
        String arguments = "ping";
        String[] cmd = {interpretor,scriptFile,arguments};
        
        try {
            Process p = Runtime.getRuntime().exec(cmd);
            ...
        

Exception:

java.io.IOException: Cannot run program "python": error=2, No such file or directory            

Any help appreciated. Thanks

0

1 Answer 1

1

Python runtime does not exist in the base image openjdk:8-jdk-alpine, you need to install it first before calling python script.

You can try below

FROM openjdk:8-jdk-alpine
RUN apk add --no-cache python
ARG JAR_FILE=target/*.jar
ARG SCRIPT_FILE=src/main/resources/script/test.py
COPY ${JAR_FILE} app.jar
COPY ${SCRIPT_FILE} test.py
ENTRYPOINT ["java","-jar","/app.jar"]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.