I have a docker image with installed python and java, and now I want to run both processes as child processes of docker.
I have checked this post which explains how to prepare image with docker and python installed. It does not explain how to get both of them running. How to run Docker with python and Java?
I checked how to run multiple processes in docker https://runnable.com/docker/rails/run-multiple-processes-in-a-container
I know it is a bad thing to run multiple processes in one container. It is an urgency and limitation, so I will stick to it for some time.
So docker documentation (above) says, prepare a shell file which starts two processes and run it inside docker file.
However!!! I connected to my docker from host command line (docker exec -it container_name bash
). I saw (top
) running processes. There is Java process running and python process is not running.
My Dockerfile
# Prepare slim python, and install open-jdk-11
ENTRYPOINT ./startJavaAndPython.sh
startJavaAndPython.sh
java -XX:+UseContainerSupport $JAVA_OPTIONS -jar java-app.jar;
python app.py;
I also read https://askubuntu.com/questions/287350/start-a-new-process-without-blocking-the-terminal
and https://unix.stackexchange.com/questions/152310/how-to-correctly-start-an-application-from-a-shell/305769, which did not work in my case. Because as you see, in my shell, if a command does not end with ;
, there will be errors when I start docker.
Updates
1) So, ampersands do not help.
startJavaAndPython.sh
java -XX:+UseContainerSupport $JAVA_OPTIONS -jar java-app.jar &;
python app.py &;
I also tried, but it did not work. startJavaAndPython.sh
java -XX:+UseContainerSupport $JAVA_OPTIONS -jar java-app.jar &
python app.py &
I received
$ docker run my-composed-task
: not foundonJava.sh: 1: ./startJavaAndPython.sh:
: not startJavaAndPython.sh: 2: ./startJavaAndPython.sh:
2) I can start my docker container, connect to it ssh, and run the python app manually. It will work!!! But how to do it automatically, without hands!
3) I use Windows 10 as a host machine.
I used these links, which might be helpful for others. https://askubuntu.com/questions/287350/start-a-new-process-without-blocking-the-terminal