运行64位CPU构架的计算机(docker目前不支持32位的cpu)docker
device Managershell
AUFSubuntu
vfsbash
默认存储驱动一般是devices mapperapp
...spa
>>> sudo docker run -i -t ubuntu /bin/bash3d
-i 保证容器中STBIN是开启的,尽管并无附着到容器中,rest
-t 则是,为建立的容器分配一个伪tty终端日志
若要在命令下建立一个咱们能与之进行交互的容器,而不是运行后台服务的容器。则这两个参数是最基本的参数了blog
>>> hostname
查看容器的主机名
>>> exit
退出
--name
docker run --name botoo_container -i -t ubuntu /bin/bash
上述命令建立一个 名为botoo_container的容器;
容器的命名必须是惟一的。
>>> sudo docker start botoo_container
或者
>>> sudo docker start 容器ID
启动已经中止的容器
当容器从新启动后,能够用dockcer attach命令 ,从新附着到该容器的会话上。
>>> docker attach 容器nane
>>> docker attach 容器ID
退出shell ,容器也中止
除了上述的交互式运行容器,也能够建立长期运行的容器。守护式容器,没交互式会话,很是适合运行应用程序和服务。
>>> sudo docker run --name daemon_dave -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done"
咱们使用一个-d参数,docker就会将容器放到后台运行。
在命令里使用一个 while循环,该循环一直打印 hello world,直到容器中止运行;
>>> sudo docker ps
能够看见该容器
获取守护容器的日志
咱们也能够使用 -f 命令 监控docker的日志,和 tail -f 命令类似。
>>> docker logs --tail 10 daemon_dave
获取日志最后10行
>>> docker logs -ft daemon_dave
... .... ....
>>> docker top 容器名
能够看容器内全部的进程;
>>> docker exece -d daemon_dave touch /etc/new_config_file
在容器中运行后台任务
>>> docker exec -t -i daemon_dave /bin/bash
在容器内运行交互命令
>>> docker stop 容器名
>>> docker stop 容器ID
>>> docker run ---restart=always --name daemon_dave -d ubuntu /bin/sh -c "while true;do echo hello world; slepp 1;done"
-- restart 设置为always ,不管容器的退出代码是什么。docker 都会自动重启该容器。
除了always ,还能够设置为 on -failure,这样,只有当容器的退出代码为非0的时候,才会自动重启。
on-failure 还接受一个重启次数参数,
--restart=on-failure:5
最多容许重启5次;
使用docker inspect 获取更多容器信息
运行中的容器是没法删除的,必须先使其stop
再删除, docker rm 容器ID