无需Dockerfile启动Docker容器

8

2
Dockerfile 用于构建镜像,而不是容器,容器就像运行这些镜像的实例。 - Webert Lima
3个回答

12
docker run -it ubuntu:16.04 bash

2
Dockerfile 描述的是 Docker 的镜像而不是容器。
容器是这个镜像的一个实例。
如果你想要运行一个容器而不需要构建一个镜像(也就是不需要创建 Dockerfile),你需要使用 Docker Hub 上现有的镜像(链接在此)。
注意:Docker Hub 是一个 Docker 在线仓库,还有其他仓库如 Quay、Rancher 等。
例如,如果你想要测试一下,你可以使用在 Docker Hub 上找到的 hello-world 镜像:https://hub.docker.com/_/hello-world/
根据文档,要运行一个简单的 hello-world 容器:
$ docker run hello-world

Source: https://hub.docker.com/_/hello-world/

如果您本地没有该镜像,Docker 将自动从网络中拉取它。如果您想手动拉取镜像,可以运行以下命令:
$ docker pull hello-world

To try something more ambitious, you can run an Ubuntu container with:

$ docker run -it ubuntu bash

Source: https://hub.docker.com/_/hello-world/


我正准备给自己答案,但你的答案可能会帮助其他新手,所以你得到了它! - basickarl
哈哈,没问题。 - Paul Rey
也许我太小气了,但是你从“hello-world”容器的输出(以及网络上的各种文档)复制了你回答中的最后两行,而没有标明它是引用,所以我要给你打-1分。 - Mark Amery

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接