How to print python statements in k8s container when running a java application through sub process

  docker, dockerfile, python, subprocess, zap

I tried making stdout, stdin as None and also subprocess.STDOUT. My container logs are still showing the logs of app.jar. I want the container to show the print statements and the application logs. Disabling logs completely is making the container print no logs. I do not want to clutter my container with application logs for viewers but want to show where the execution is currently

**code.py**
pro = subprocess.Popen(
    ['/bin/java', '-jar', '/apps/ZAP_2.10.0/app.jar',
     '-daemon', '-host', 'localhost', '-port', '8080', '-dir', '', '-silent', '-config', 'api.key=ZAP',
     '-config', 'api.addrs.addr.regex=true', '-config', 'connection.timeoutInSecs=300'], shell=False,
    stdin=None, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, close_fds=True)


print("App is running!")

Docker File:

RUN wget app.zip &&
       unzip app.zip 
       rm -f app.zip
CMD ["/bin/bash", "script.sh"]

My script.sh file:

#!/bin/bash`
source venv/bin/activate`
python code.py

My code.py has the content I mentioned in the question. I am deploying it as ‘Deployment’ config.

Source: Dockerfile Questions

LEAVE A COMMENT