Docker学习笔记(4-2)Docker 操作守护式容器
守护式容器:长期在后台运行,没有交互式操作,适合运行应用程序和服务
docker run -i -t IMAGE /bin/bash
CTRL+P OR CTRL+Q
docker run -d IMAGE /bin/bash
docker attach xxxxxxx
执行exit后容器停止
CTRL+P CTRL+Q后台运行
docker run --name dc1 -d ubuntu /bin/sh -c "while true; do echo hello world ; sleep 1; done"
-d 后台方式运行,运行完成还会停止
所以此处用循环
docker ps
docker logs [-f] [-t] [--tail] 容器名
-f
-t
--tail=“all”
无参数:返回所有日志
-f 一直跟踪变化并返回
-t 带时间戳返回
-tail 返回结尾处指定数量日志
ctrl+c停止返回
docker -tf --tail 10 dc1 # 最近10条
docker -tf --tail 0 dc1 # 最新的日志
docker ps
doker top dc1 # 容器情况
# 在运行中的容器内启动新进程
docker exec [-d] [-i] [-t] 容器名 [command] [args]
docker exec -i -t dc1 /bin/bash
ctrl+p ctrl+q
docker top dc1 #发现bash的进程运行在dc1中。
# 停止守护式容器
docker stop 容器名 # 发结束信号,等待容器停止后返回
docker kill 容器名 # 直接停止容器并返回
原文:http://www.cnblogs.com/lexiaofei/p/6361603.html