如果Docker容器立即退出该怎么办

If you run a container using docker run and it immediately exits and every time you press the Start button in Docker Desktop it exits again, there is a problem.

如果您使用docker run运行一个容器,并且该容器立即退出,并且每次在Docker Desktop中按下“开始”按钮时,该容器都会再次退出,则存在问题。

如果Docker容器立即退出该怎么办

The way to figure out what is wrong is to run docker logs, adding the name of the container at the end:

找出错误的方法是运行docker logs ,并在末尾添加容器名称:

如果Docker容器立即退出该怎么办

You can also click the Container name in Docker Desktop, and it will show a list of logs:

您还可以在Docker Desktop中单击Container名称,它将显示日志列表:

如果Docker容器立即退出该怎么办

In this case after a quick Google search I realized I used a single quote in my CMD command.

在这种情况下,经过Google的快速搜索后,我意识到我在CMD命令中使用了单引号。

Note that to fix problems like this, you need to remove the container, but also delete the image and rebuild it.

请注意,要解决此类问题,您需要删除容器,还要删除映像并重新生成它。




翻译自: https://flaviocopes.com/docker-container-exits/