启动Docker容器后,对应的服务(例如tomcat启动)也通过dockerfile文件命令运行起来了,这个时候如何进行容器内部观察容器的运行状态。
1.docker attach 这个命令在创建一个守护态的Docker容器,然后使用docker attach命令进入该容器。
2.docker exec 这个命令比较方便,可以在容器运行别的服务时连接上该容器
进入容器命令
sudo docker exec -it containerID /bin/bash
实例操作如下
进入,ping宿主机IP地址:
[[email protected] ~]# sudo docker exec -it 4be093b46d22 /bin/bash [[email protected] /]# ping 10.10.11.218 PING 10.10.11.218 (10.10.11.218) 56(84) bytes of data. 64 bytes from 10.10.11.218: icmp_seq=1 ttl=64 time=0.037 ms 64 bytes from 10.10.11.218: icmp_seq=2 ttl=64 time=0.021 ms 64 bytes from 10.10.11.218: icmp_seq=3 ttl=64 time=0.014 ms 64 bytes from 10.10.11.218: icmp_seq=4 ttl=64 time=0.020 ms 64 bytes from 10.10.11.218: icmp_seq=5 ttl=64 time=0.020 ms 64 bytes from 10.10.11.218: icmp_seq=6 ttl=64 time=0.017 ms 64 bytes from 10.10.11.218: icmp_seq=7 ttl=64 time=0.017 ms 64 bytes from 10.10.11.218: icmp_seq=8 ttl=64 time=0.018 ms 64 bytes from 10.10.11.218: icmp_seq=9 ttl=64 time=0.015 ms 64 bytes from 10.10.11.218: icmp_seq=10 ttl=64 time=0.014 ms 64 bytes from 10.10.11.218: icmp_seq=11 ttl=64 time=0.022 ms ^Z [1]+ Stopped ping 10.10.11.218 [[email protected] /]# ls anaconda-post.log bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var [[email protected] /]# cd /usr/local [[email protected] local]# ls apache-tomcat-8.5.16 bin etc games include jdk1.8.0_121 lib lib64 libexec sbin share src [[email protected] local]#
ping外网地址:
[[email protected] local]# ping www.baidu.com PING www.a.shifen.com (115.239.211.112) 56(84) bytes of data. 64 bytes from 115.239.211.112 (115.239.211.112): icmp_seq=1 ttl=51 time=7.85 ms 64 bytes from 115.239.211.112 (115.239.211.112): icmp_seq=2 ttl=51 time=7.95 ms 64 bytes from 115.239.211.112 (115.239.211.112): icmp_seq=3 ttl=51 time=6.98 ms 64 bytes from 115.239.211.112 (115.239.211.112): icmp_seq=4 ttl=51 time=7.52 ms 64 bytes from 115.239.211.112 (115.239.211.112): icmp_seq=5 ttl=51 time=7.62 ms 64 bytes from 115.239.211.112 (115.239.211.112): icmp_seq=6 ttl=51 time=7.40 ms 64 bytes from 115.239.211.112 (115.239.211.112): icmp_seq=7 ttl=51 time=7.90 ms 64 bytes from 115.239.211.112 (115.239.211.112): icmp_seq=8 ttl=51 time=7.99 ms 64 bytes from 115.239.211.112 (115.239.211.112): icmp_seq=9 ttl=51 time=7.73 ms 64 bytes from 115.239.211.112 (115.239.211.112): icmp_seq=10 ttl=51 time=8.00 ms ^Z [2]+ Stopped ping www.baidu.com [[email protected] local]#
Docker新认知
Docker容器是一个系统级别的服务,拥有自己的IP和系统目录结构,所以我们完全可以认为一个运行的容器就是一个运行的虚拟机。
判断网络通不通:我们可以在Docker外部的宿主机和Docker容器之间进行互ping测试。
进入Docker容器比较常见的几种做法
- 使用docker attach
- 使用SSH
- 使用nsenter
- 使用exec
时间: 2024-10-22 20:59:07