如何进入到Docker容器内部

启动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

转载于:https://www.cnblogs.com/boonya/p/7376489.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值