search

Home  >  Q&A  >  body text

The image exits by itself after docker run it. How to prevent it from exiting?

As the title says,

sudo docker run -it resin/rpi-raspbian /bin/bash

Theoretically speaking, bash has not been closed and should be usable, but why, check after each run

sudo docker ps 

There are no running images.
pass

sudo docker run -it resin/rpi-raspbian /bin/echo "hello world"

//或者

sudo docker ps -a

It can be verified that docker has been executed and then exited. Adding the -it command should enter the bash of the image and then interact, but it does not. How to deal with this situation...

Docker version 1.12.6, build 78d1802

怪我咯怪我咯2774 days ago1020

reply all(2)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-24 11:34:56

    Your question 1

    1. Docker run -it Please do not use CTRL+C退出
    2.使用CTRL+P+Q to exit the internal session of the current container, it will run in the background.

    If your problem is not solved, please try to check the log information

    $docker logs ${container_id}

    Your next question

    Docker will default the internal pid of the container to 1 as the identifier. If 1 dies, the container will die. After echo "hello", the pid will die, and then the natural container will die.

    Documentation

    In the official documentation, the use of run -it in the docker cli introduction is as follows
    Docs

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-24 11:34:56

    Because you didn’t add the -d parameter

    reply
    0
  • Cancelreply