运行一个docker
docker run -i -t ubuntu:15.10 /bin/bash
运行的docker镜像是ubuntu:15.10
-t :在新容器中指定一个终端
-i: 允许容器中的标准输入进行交互
/bin/bash 在容器里运行程序/bin/bash
如果要后台启动添加参数-d
查看容器
docker ps
Options:
-a, --all Show all containers (default shows just running)
-f, --filter filter Filter output based on conditions provided
–format string Pretty-print containers using a Go template
–help Print usage -n, --last int Show n last created containers (includes all states) (default -1) -l,
–latest Show the latest created container (includes all states)
–no-trunc Don’t truncate output
-q, --quiet Only display numeric IDs
-s, --size Display total file sizes
停止容器
docker stop [容器id]
删除容器
docker rm [容器id]
删除所有容器
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
删除镜像
docker rmi [镜像名]
创建容器,但不运行它
docker create [镜像名]
得到的容器id可以保存到一个shell变量里,也可以写到文件里
[root@localhost ~]# echo $cid
a49d4c2a16c7c325ffb42a13173645118e096fe76335aa1c00b76b3760525217
[root@localhost ~]# docker create --cidfile /tmp/ng.cid nginx
44b7253dc93dd9576057397884a7d75a5eaea84136fd381f175c5cd64e1ee52e
[root@localhost ~]# cat /tmp/ng.cid
44b7253dc93dd9576057397884a7d75a5eaea84136fd381f175c5cd64e1ee52e
启动容器
docker start [容器id
]
运行容器中的程序
docker exec [容器id/容器名] ps