美文网首页
Docker教程:4 hello world实例

Docker教程:4 hello world实例

作者: 海涛666 | 来源:发表于2016-09-22 16:49 被阅读0次

英文原文:[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

相关文章

网友评论

      本文标题:Docker教程:4 hello world实例

      本文链接:https://www.haomeiwen.com/subject/gogrettx.html