0

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

https://unix.stackexchange.com/questions/152310/how-to-correctly-start-an-application-from-a-shell/305769

How do I get into a Docker container's shell?

7
  • 1
    And if you connect to the container and type the command to start the python script manually? Do you get an error or is the process starting? Commented Feb 5, 2019 at 14:51
  • No! I ssh my docker, and started python app manually. it worked!!! Commented Feb 5, 2019 at 14:53
  • 1
    Is the python process depending on the java process? If so it is possible that when the python starts the java program has not yet started and so you have a failure Commented Feb 5, 2019 at 14:55
  • 3
    Why do you need to end commands with a semicolon? I've never seen that before. Can you not run your entrypoint script with bash? Commented Feb 5, 2019 at 14:57
  • 1
    So both of your java and python processes run for the lifetime of the container? Commented Feb 5, 2019 at 15:01

1 Answer 1

1

After much pain. As I said, I use Windows. It does append \r at the end of each line. Then my shell script has these endings and fails to start. More exactly, it starts first command - which is to start java, but it never executes the second command, which starts python.

startJavaAndPython.sh

java -XX:+UseContainerSupport $JAVA_OPTIONS -jar sidecarForPythonService-app.jar & python app.py;

If you have other details, feel free to answer.

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.