惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

TaoSecurity Blog
TaoSecurity Blog
L
LINUX DO - 最新话题
Help Net Security
Help Net Security
N
News | PayPal Newsroom
www.infosecurity-magazine.com
www.infosecurity-magazine.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
The Last Watchdog
The Last Watchdog
S
Security @ Cisco Blogs
W
WeLiveSecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
Webroot Blog
Webroot Blog
T
Troy Hunt's Blog
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
N
News and Events Feed by Topic
T
Threat Research - Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tor Project blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
D
Darknet – Hacking Tools, Hacker News & Cyber Security
PCI Perspectives
PCI Perspectives
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
S
SegmentFault 最新的问题
J
Java Code Geeks
P
Privacy & Cybersecurity Law Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 【当耐特】
博客园_首页
H
Hacker News: Front Page
T
Threatpost
Jina AI
Jina AI
博客园 - Franky
月光博客
月光博客
L
LINUX DO - 热门话题
The Cloudflare Blog
H
Heimdal Security Blog
博客园 - 司徒正美
酷 壳 – CoolShell
酷 壳 – CoolShell
Cloudbric
Cloudbric
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
S
Secure Thoughts
T
Tenable Blog
I
Intezer
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

mafeifan 的编程技术分享

mafengwo-mp3-downloader | mafeifan 的编程技术分享 示例页面 | mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 查看 default namespace 下的 default service account名称 mafeifan 的编程技术分享 检查日志 | mafeifan 的编程技术分享 bridge fdb show dev flannel.1 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 数据收集原理分析 | mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 几种方法 | mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 check the export on the very top of this document so we can use $do mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 运维自动化之ANSIBLE | mafeifan 的编程技术分享 延伸 -- 关于前端路由 xdebug 3 和 2 的区别
mafeifan 的编程技术分享
2026-01-16 · via mafeifan 的编程技术分享

Jenkins是在Docker容器里内跑的,现在需要Jenkins进到外部的宿主机并执行命令。

这里牵涉到两个问题:

  1. 我如何知道宿主机的IP
  2. 我如何通过IP访问宿主机

第1个问题,获取宿主机的IP ​

方法1:宿主机执行ifconfig

br-afd31e8abae9: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.22.0.1  netmask 255.255.0.0  broadcast 172.22.255.255
        inet6 fe80::42:a9ff:fea7:24d4  prefixlen 64  scopeid 0x20<link>
        ether 02:42:a9:a7:24:d4  txqueuelen 0  (Ethernet)
        RX packets 5566  bytes 1789941 (1.7 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8811  bytes 75927547 (75.9 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:63ff:fe9f:9251  prefixlen 64  scopeid 0x20<link>
        ether 02:42:63:9f:92:51  txqueuelen 0  (Ethernet)
        RX packets 18693  bytes 5563196 (5.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 23271  bytes 122914964 (122.9 MB)
        TX errors 0  dropped 0 overr+uns 0  carrier 0  collisions 0

会看到docker0中的inet,172.17.0.1就是docker中的IP。而宿主机的内部IP是172.22.0.1

如果进到Jenkins容器,直接ping这个地址是通的。

但问题是这个IP不一定是固定的,我们需要在启动Jenkins容器时将当前的宿主IP告诉容器。

方法2:容器内执行ip route show | awk '/default/ {print $3}'

方法3:解决方案

如果在MacOS或Windows运行docker,尝试直接在容器内运行ping host.docker.internal返回的是宿主机IP

对于Linux,在docker-compose.yaml加入

注:需要docker版本在20.04及以上

我们更新docker-compose.yml

extra_hosts:
- "host.docker.internal:host-gateway"

重新进到容器内,查看hosts文件 cat /etc/hosts 就会发现新增了一条172.17.0.1 host.docker.internal 直接ping host.docker.internal可以连通

如果docker-compose.yml

extra_hosts:
 - "somehost:162.242.195.82"
 - "otherhost:50.31.209.229"

/etc/hosts 就会看到

162.242.195.82  somehost
50.31.209.229   otherhost

第2个问题,通过SSH协议访问宿主机 ​

这个简单,我们需要进到容器内,只需要生成一对密钥。然后再将ssh目录映射出来

假设有一正在运行的容器,名称为: jenkins_jenkins-compose

登录宿主机,将容器内的ssh目录拷贝到宿主机中 docker cp jenkins_jenkins-compose:/root/.ssh ssh

设置权限和所属

chown root:root -R ~/.ssh/
chmod 600 ~/.ssh/config

修改docker-compose

volumes:
 - /var/run/docker.sock:/var/run/docker.sock
 - /usr/bin/docker:/usr/bin/docker
 # 加入这行
 - /home/ubuntu/docker/jenkins/ssh:/root/.ssh

关于ssh/config文件

Host cloud2
    HostName host.docker.internal
    User ubuntu
    Port 22
    IdentityFile ~/.ssh/id_rsa

测试: 在容器内执行 ssh cloud2 ls,相当于进到cloud2主机,并执行ls命令,返回结果正常

参考 ​

https://stackoverflow.com/questions/31324981/how-to-access-host-port-from-docker-container/61424570#61424570

https://github.com/qoomon/docker-host

https://stackoverflow.com/questions/52925194/how-to-run-shell-script-on-host-from-jenkins-docker-container

https://stackoverflow.com/questions/32163955/how-to-run-shell-script-on-host-from-docker-container