Docker 容器不是 运行 用于简单文件

Docker container not running for a simple file

FROM ubuntu

RUN apt-get update && apt-get install -y vim

以上是我在 docker 文件中的所有内容,只需在 ubuntu

上安装 vim

我运行这个在本地使用

docker build -t myFirstUbuntuimage .

那么如果我运行容器使用上面的图片作为

docker run -d --name myfirstcontainer myFirstUbuntuimage:latest

容器没有 运行。我怎样才能做到 运行?

docker ps 显示为空

容器可能 运行ning 就好了。 ubuntu 图像的默认行为是启动交互式 shell,但由于您启动的是非交互式容器,因此 shell 将立即退出。

当您 运行 容器时,您期望 发生什么?

如果您删除 -d 并添加 -it,您将获得交互式 shell:

docker run -it --name myfirstcontainer myFirstUbuntuimage:latest