简体   繁体   中英

docker container exited immediately after python script execution

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 ...."

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM