摘取自learning docker.pdf
docker早起是没有内置debug功能的,而debug多是社区的开源贡献者的,后来docker内置了这项功能
1.exec
Now, it is not necessary to log in to run the SSH daemon in the container.
使用exec登录
root@VM-87-81-debian:~# clear
root@VM-87-81-debian:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
be0967ec7e63 busybox:latest "/bin/sh" 22 hours ago Up 22 hours datavol
c596bd8f836b diancloud/ghost:0.6.3-zh "bash /ghost/ghost-st" 43 hours ago Up 43 hours 0.0.0.0:80->2368/tcp diancloud-ghost
root@VM-87-81-debian:~# docker exec -it be sh
/ #
/ #
注意:
It is recommended that you use the docker exec command only for monitoring
and diagnostic purposes, and I personally believe in the concept of one process per
container, which is one of the best practices widely accentuated.
2.ps
这是可以查看容器的state,不过多介绍
3.上面是需要在容器里面才能执行的,我们也可以不登录主机情况下直接使用top
root@VM-87-81-debian:~# docker top be
UID PID PPID C STIME TTY TIME CMD
root 31729 31711 0 Jun24 pts/0 00:00:00 /bin/sh
也可以在容器里面执行top查看更加详细的report
4.stats
stats用来查看该容器占用主机的cpu,内容等资源情况
The Docker stats command provides you with the capability to view the memory, CPU, and the network usage of a container from a Docker host machine
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
be 0.00% 0 B / 0 B 0.00% 6.324 kB / 648 B 0 B / 0 B 0
5.events
Docker containers will report the following real-time events:
create, destroy, die,export, kill, omm, pause, restart, start, stop, and unpause
6.logs
^Croot@VM-87-81-debian:~# docker logs be
/ # ls
DataMount bin dev etc home proc root sys tmp usr var
/ # cd DataMount/
/DataMount # ls
/DataMount # ls
aa.cc
root@VM-87-81-debian:~#