1

I have spring boot java application . For some of its api, it calls a python program(which is present in src folder e.g. abc.py) to get the output.

I have a dockerfile to dockerize the application. I am able to successfully build the image and container is runnning out of the image . But when I call the api , it throws error and says python command not found . Also when I go inside docker container , when I check for 'which python' , it does not show anything.

For python install and making python environment variable set inside this docker , what should be mentioned in the dockerfile.

FROM gradle:4.10.1-jdk8-alpine AS build
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle build --no-daemon

FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir -p /dispython
WORKDIR /dispython
COPY requirements.txt /dispython
RUN pip install --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt
RUN python --version
RUN which python
#ENV PYTHONPATH "${PYTHONPATH}:/dispython"


FROM openjdk:8-jre-slim

EXPOSE 8081

RUN mkdir /app

COPY --from=build /home/gradle/src/build/libs/*.jar /app/spring-boot 
application.jar

ENTRYPOINT ["java", "-XX:+UnlockExperimentalVMOptions", "- 
             XX:+UseCGroupMemoryLimitForHeap", "- 
             Djava.security.egd=file:/dev/./urandom","-jar","/app/spring- 
             boot-application.jar"]

Advance thanks

  • You should create a `docker-compose.yml` if you want to run several containers (eg. Java app and Python app). Please show your `Dockerfile` for us to be able to guide you. – k-wasilewski Jul 19 '20 at 09:15
  • Hey @k-wasilewski, thank you for the reply. yes just now i added the docker file. is it not possible to run in one container ??? – user3631074 Jul 19 '20 at 09:18
  • is it not possible that the container has just python installed so that java can understand the python and will be execute the the python programm. I have just one python file in this spring boot application – user3631074 Jul 19 '20 at 09:22
  • Technically it's sound (see here https://stackoverflow.com/questions/27664820/running-multiple-applications-in-one-docker-container), just not common for the reasons mentioned. – k-wasilewski Jul 19 '20 at 09:23
  • the link you shared is about multiple applications...here in my case java is the application.. Just it wants to execute a python program on demand..I dont want python will be executed at the start of the container....when i do which java it shows java path but when i do which python , it does not show..anything I am missing ??? – user3631074 Jul 19 '20 at 10:08
  • "which python" gives the output when building image...but when inside container, why it is not showing ?? and the directory /dispython I created during image, it is not present in the container.. Might be I am the ignorant here to use docker...if you give insight , it will be helpful.. – user3631074 Jul 19 '20 at 10:11
  • `RUN` commands run at the building container phase. As for your `mkdir` - it looks correct. I have no exp with Python, so let's leave the rest to someone who does :) – k-wasilewski Jul 19 '20 at 10:16

1 Answers1

-1

If you really don't want to use docker-compose (recommended), you still have to copy this *.py file to your container COPY src/ src/...

k-wasilewski
  • 3,943
  • 4
  • 12
  • 29