英文原文:[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
网友评论