Why docker container exits immediately

后端 未结 15 2239
温柔的废话
温柔的废话 2020-11-22 13:42

I run a container in the background using

 docker run -d --name hadoop h_Service

it exits quickly. But if I run in the foreground, it works

15条回答
  •  粉色の甜心
    2020-11-22 14:42

    A docker container exits when its main process finishes.

    In this case it will exit when your start-all.sh script ends. I don't know enough about hadoop to tell you how to do it in this case, but you need to either leave something running in the foreground or use a process manager such as runit or supervisord to run the processes.

    I think you must be mistaken about it working if you don't specify -d; it should have exactly the same effect. I suspect you launched it with a slightly different command or using -it which will change things.

    A simple solution may be to add something like:

    while true; do sleep 1000; done

    to the end of the script. I don't like this however, as the script should really be monitoring the processes it kicked off.

    (I should say I stole that code from https://github.com/sequenceiq/hadoop-docker/blob/master/bootstrap.sh)

提交回复
热议问题