2

docker container exited immediately after python script execution:

docker run -t -i -v /root/test.py:/test.py zookeeper python test.py (test.py starts zookeeper service )

The command is successful but exits immediately with out starting container. I could NOT start the container with "docker start container id".

Manually running "python test.py" is successful inside container but not during "docker run ...."

1 Answer 1

6

Just starting the server is not enough. When the CMD exits, so does the container. Thus, if you start a service that's a daemon, you need to keep your process alive. This can be achieved by, for example, tailing the service log file. supervisord is another way to run processes and keep the CMD alive.

For example, you might do

CMD /test.py && tail -F /var/log/zookeeper.log

Running from the commandline you could do something similar

docker run -t -i -v /root/test.py:/test.py zookeeper bash -c "python test.py && tail -F /var/log/zookeeper.log"
Sign up to request clarification or add additional context in comments.

2 Comments

Excellent it worked. I know it's executing and getting out, but didn't know how to handle the situation. Thank u.
There should be a check mark next to the answer. You can just click it.

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.