docker基本使用

运行一个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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值