Docker教程:4 hello world实例

英文原文:[https://docs.docker.com/engine/tutorials/dockerizing/]

运行一个Hello world容器

$ docker run ubuntu /bin/echo 'Hello world'
Hello world

这个示例中:

  • docker run
    运行一个容器
  • ubuntu
    我们要运行的一个image(Docker首先会在本地查找image,找不到时从Docker Hub上pull下来)
  • /bin/echo
    我们要在这个新的容器中所要运行的命令

So what happened to the container after that? Well, Docker containers only run as long as the command you specify is active. Therefore, in the above example, the container stops once the command is executed.

docker容器什么时候结束是根据我们所指定的命令的运行情况决定的。

运行一个交互式容器

$ docker run -t -i ubuntu /bin/bash

-t
说明新的容器中包含一个虚拟的终端控制台
-i
说明这个命令是可交互式的(可以接收用户的输入)

容器启动后:

root@af8bae53bdd3:/#

我们可以输入一些/bin/bash中的命令进行测试:

root@af8bae53bdd3:/# pwd
/
root@af8bae53bdd3:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容