docker run
docker run
常用命令
后台启动
docker run -d centos (他没有前台应用,他就给你停掉了)
docker ps (centos停止了)
后台运行没有前台进程 容器发现没有应用。(对外提供服务) 很节能
查看日志命令
docker run -d centos /bin/sh -c "while true;do echo maoqiyang;sleep 1;done"
docker ps (查看正在运行的容器)
docker logs -tf --tail 10 ac932be60f16 (不加tail就是全部) 查看日志
tail [num] 条数 -tf 显示日志与时间
docker top id (查看进程信息)
docker inspect id (查看容器元数据)
进入后台的容器
docker exec -it 容器id bashshell
docker exec -it cb4fa92943e1 /bin/bash (打开新的bash进去)
docker attach 容器id (进入执行的命令行)
docker cp 容器id
docker cp bfe0b8eca166:/home/mqy.heihei ./
从容器里拷贝文件
进入容器内,新建文件,并拷贝到主机上
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bfe0b8eca166 centos "/bin/bash" 10 minutes ago Exited (0) About a minute ago unruffled_goldwasser
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bfe0b8eca166 centos "/bin/bash" 10 minutes ago Exited (0) 2 minutes ago unruffled_goldwasser
[root@docker ~]# docker start bfe0b8eca166
bfe0b8eca166
[root@docker ~]# docker attach bfe0b8eca166
[root@bfe0b8eca166 /]# cd /home
[root@bfe0b8eca166 home]# ls
abc mqy.heihei
[root@bfe0b8eca166 home]# mkdir axe
[root@bfe0b8eca166 home]# exit
exit
[root@docker ~]# docker cp bfe0b8eca166:/home/axe ./
[root@docker ~]#