Why can’t the docker container start?

  docker, question

After sudo docker run -d centos /bin/bash created the container, use docker ps -a to find that the container has stopped. After using docker start id to start the container, observe the operation time of ps -a and find that the container has actually started but stopped immediately. What is the reason?

Add: Try to start three kinds of images, centos,mysql,nginx nginx, and only NGINX can start. The other two cannot be activated.
图片描述

Supplement 2: The problem has been basically found. The reason is that there must be a foreground process when the Docker container runs in the background. When the main thread ends, the container exits.
Sudokkerrun-dcentos should be changed to sudokkerditcentos.
I always feel a little uncomfortable. Do you have any better solutions? I hope you can give me your advice. . .

The output of the main program of the container can be viewed through the docker logs container ID. Try to analyze the reason through this.

In addition, the default startup of the system image is bash. if there is no input stream connection, the system image itself will end immediately.