Why docker container exits immediately

后端 未结 15 2191
温柔的废话
温柔的废话 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:38

    I would like to extend or dare I say, improve answer mentioned by camposer

    When you run

    docker run -dit ubuntu
    

    you are basically running the container in background in interactive mode.

    When you attach and exit the container by CTRL+D (most common way to do it), you stop the container because you just killed the main process which you started your container with the above command.

    Making advantage of an already running container, I would just fork another process of bash and get a pseudo TTY by running:

    docker exec -it  /bin/bash
    

提交回复
热议问题