天下之事,必先处之难,而后易之。
君临
知我者谓我心忧,不知我者谓我何求

启动Docker容器后,对应的服务(例如tomcat启动)也通过dockerfile文件命令运行起来了,这个时候如何进行容器内部观察容器的运行状态。

1.docker attach 这个命令在创建一个守护态的Docker容器,然后使用docker attach命令进入该容器。

2.docker exec 这个命令比较方便,可以在容器运行别的服务时连接上该容器

进入容器命令

sudo docker exec -it containerID /bin/bash 

实例操作如下

进入,ping宿主机IP地址:

[root@mysqlserver ~]# sudo docker exec -it 4be093b46d22  /bin/bash 
[root@4be093b46d22 /]# 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
[root@4be093b46d22 /]# ls
anaconda-post.log  bin    dev  etc  home    lib  lib64  lost+found    media  mnt  opt  proc  root  run  sbin    srv  sys  tmp  usr  var
[root@4be093b46d22 /]# cd /usr/local
[root@4be093b46d22 local]# ls
apache-tomcat-8.5.16  bin  etc    games  include    jdk1.8.0_121  lib  lib64  libexec  sbin  share    src
[root@4be093b46d22 local]# 
 

ping外网地址:

[root@4be093b46d22 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
[root@4be093b46d22 local]# 

Docker新认知

Docker容器是一个系统级别的服务,拥有自己的IP和系统目录结构,所以我们完全可以认为一个运行的容器就是一个运行的虚拟机。

判断网络通不通:我们可以在Docker外部的宿主机和Docker容器之间进行互ping测试。

 

进入Docker容器比较常见的几种做法

  • 使用docker attach
  • 使用SSH
  • 使用nsenter
  • 使用exec
posted on 2017-08-16 22:56  boonya  阅读(2776)  评论(0编辑  收藏  举报

我有佳人隔窗而居,今有伊人明月之畔。
轻歌柔情冰壶之浣,涓涓清流梦入云端。
美人如娇温雅悠婉,目遇赏阅适而自欣。
百草层叠疏而有致,此情此思怀彼佳人。
念所思之唯心叩之,踽踽彳亍寤寐思之。
行云如风逝而复归,佳人一去莫知可回?
深闺冷瘦独自徘徊,处处明灯影还如只。
推窗见月疑是归人,阑珊灯火托手思忖。
庐居闲客而好品茗,斟茶徐徐漫漫生烟。

我有佳人在水之畔,瓮载渔舟浣纱归还。
明月相照月色还低,浅近芦苇深深如钿。
庐山秋月如美人衣,画堂春阁香气靡靡。
秋意幽笃残粉摇曳,轻轻如诉画中蝴蝶。
泾水潺潺取尔浇园,暮色黄昏如沐佳人。
青丝撩弄长裙翩翩,彩蝶飞舞执子手腕。
香带丝缕缓缓在肩,柔美体肤寸寸爱怜。
如水之殇美玉成欢,我有佳人清新如兰。
伊人在水我在一边,远远相望不可亵玩。