测试工程师Docker基础 (3)

列出所有运行的容器

#docker ps #列出当前正在运行的容器 Options: -a, --all Show all containers (default shows just running)#列出目前所有容器 -q, --quiet Only display numeric IDs #只显示容器id [root@ecs-x-large-2-linux-20200305213344 ~]# docker ps -aq #显示所有容器id 9f5b41ce646c 7aab85f14183

退出容器

exit #退出容器

删除容器

docker rm 容器id #删除指定的容器,不能删除正在运行的容器,如果要强制删除 rm -rf docker rm -f $(docker ps -aq) #删除指定的容器 docker ps -a -q|xargs docker rm #删除所有的容器

启动和停止容器

docker start 容器id #启动容器 docker restart 容器id #重启容器 docker stop 容器id #停止当前正在运行的容器 docker kill 容器id #强制停止当前容器

查看日志

[root@ecs-x-large-2-linux-20200305213344 ~]# docker logs --help Options: --details Show extra details provided to logs -f, --follow Follow log output --help Print usage --since string Show logs since timestamp --tail string Number of lines to show from the end of the logs (default "all") -t, --timestamps Show timestamps #显示日志 -tf #显示日志信息(一直更新) --tail number #需要显示日志条数 docker logs -t --tail n 容器id #查看n行日志 docker logs -ft 容器id #跟着日志

查看容器中的进程信息

#docker top 容器id [root@ecs-x-large-2-linux-20200305213344 ~]# docker top cacf7a960d29 UID PID PPID C STIME TTY TIME CMD root 27859 27841 0 16:26 ? 00:00:00 nginx: master process nginx -g daemon off; 101 27908 27859 0 16:26 ? 00:00:00 nginx: worker process

查看容器元数据

#docker inspect 容器id [root@ecs-x-large-2-linux-20200305213344 ~]# docker inspect cacf7a960d29 [ { "Id": "cacf7a960d29dc24755f6b9896aaa85f2e9f902ff7f620470c907acf5e17bd7a", "Created": "2021-03-06T08:26:19.015315592Z", "Path": "/docker-entrypoint.sh", "Args": [ "nginx", "-g", "daemon off;" ], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 27859, "ExitCode": 0, "Error": "", "StartedAt": "2021-03-06T08:26:19.32665951Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "sha256:35c43ace9216212c0f0e546a65eec93fa9fc8e96b25880ee222b7ed2ca1d2151", "ResolvConfPath": "/var/lib/docker/containers/cacf7a960d29dc24755f6b9896aaa85f2e9f902ff7f620470c907acf5e17bd7a/resolv.conf", "HostnamePath": "/var/lib/docker/containers/cacf7a960d29dc24755f6b9896aaa85f2e9f902ff7f620470c907acf5e17bd7a/hostname", "HostsPath": "/var/lib/docker/containers/cacf7a960d29dc24755f6b9896aaa85f2e9f902ff7f620470c907acf5e17bd7a/hosts", "LogPath": "", "Name": "/nginx01", "RestartCount": 0, "Driver": "overlay2", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": {

进入当前正在运行的容器

#我们通常容器都是在后台运行方式,如果需要修改一些配置或其他操作,那么我们需要进入运行的容器 #方式一:docker exec - it容器id /bin/bash [root@ecs-x-large-2-linux-20200305213344 ~]# docker exec -it cacf7a960d29 /bin/bash root@cacf7a960d29:/# ls bin dev docker-entrypoint.sh home lib64 mnt proc run srv tmp var boot docker-entrypoint.d etc lib media opt root sbin sys usr #方式二:docker attach 容器id [root@ecs-x-large-2-linux-20200305213344 ~]# docker attach cacf7a960d29 正在执行的代码****** [root@ecs-x-large-2-linux-20200305213344 ~]# #ctrl+c 退出 #区别 #docker exec #进入当前容器后开启一个新的终端,可以在里面操作。(常用) #docker attach # 进入容器正在执行的终端

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyffwy.html