解決docker安裝jenkins容器內(nèi)無法訪問外網(wǎng)
1. 問題描述
云容器中安裝了jenkins, 但是在頁面上進(jìn)入"Manage Plugins"的"update"選項(xiàng)卡最下面檢查時(shí), 顯示:
Update information obtained: N/A ago
但是我實(shí)際上填寫的Update Site
是能很快訪問的 http://updates.jenkins.io/current/update-center.json
2. 問題猜測(cè)
所以懷疑是docker內(nèi)部的jenkins,訪問不了上面的網(wǎng)址。為了確認(rèn), 我在系統(tǒng)里登錄docker查看是否能訪問外網(wǎng):
[root@root ~]$ docker exec -it jenkins /bin/bash bash-5.1# curl www.baidu.com curl: (6) Could not resolve host: www.baidu.com
果然訪問不了。
3.解決docker內(nèi)部jenkins不能訪問外網(wǎng)地址問題:
3.1 查看宿主機(jī)防火墻NAT轉(zhuǎn)發(fā)
1.退出docker
exit
2.檢查宿主機(jī)防火墻轉(zhuǎn)發(fā)
[root@root ~]$ firewall-cmd --query-masquerade FirewallD is not running [nie@nie ~]$ systemctl start firewalld.service # 切換root身份 [nie@nie ~]$ su root [root@nie nie]# firewall-cmd --query-masquerade no
no 確實(shí)沒;
masquerade /?mæsk??re?d/
n.掩藏,掩飾;偽裝,化裝;欺騙;化妝舞會(huì) v.偽裝,化裝;冒充
檢查配置轉(zhuǎn)發(fā),沒有則加入net.ipv4.ip_forward = 1
sysctl -p vi /etc/sysctl.conf net.ipv4.ip_forward = 1
開啟轉(zhuǎn)發(fā)
[root@nie nie]# firewall-cmd --add-masquerade --permanent success [root@nie nie]# firewall-cmd --query-masquerade no # 需要重新加載 [root@nie nie]# firewall-cmd --reload success [root@nie nie]# firewall-cmd --query-masquerade yes
重啟docker
systemctl restart docker
4. 再試docker內(nèi)訪問外網(wǎng)
[root@nie nie]# docker exec -it jenkins /bin/bash bash-5.1# curl www.baidu.com <!DOCTYPE html> <!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新聞</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地圖</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>視頻</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>貼吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登錄</a> </noscript> <script>document.write('<a + encodeURIComponent(window.location.href+ (window.location.search === " rel="external nofollow" " ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登錄</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多產(chǎn)品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>關(guān)于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a href=http://www.baidu.com/duty/>使用百度前必讀</a> <a href=http://jianyi.baidu.com/ class=cp-feedback>意見反饋</a> 京ICP證030173號(hào) <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>
OK finished~
以上就是解決docker安裝jenkins容器內(nèi)無法訪問外網(wǎng)的詳細(xì)內(nèi)容,更多關(guān)于docker安裝jenkins訪問外網(wǎng)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
docker部署crownblog項(xiàng)目到阿里云的方法步驟
這篇文章主要介紹了docker部署crownblog項(xiàng)目到阿里云的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05Windows11安裝Docker Desktop教程的圖文教程
本文主要介紹一下Windows11安裝Docker Desktop教程的圖文教程,文中通過圖文介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-10-10Mac?M1?Docker如何運(yùn)行nacos2.0.3(若依微服務(wù)框架)
這篇文章主要介紹了Mac?M1?Docker如何運(yùn)行nacos2.0.3(若依微服務(wù)框架),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12Docker創(chuàng)建本地鏡像實(shí)現(xiàn)方法解析
這篇文章主要介紹了Docker創(chuàng)建本地鏡像實(shí)現(xiàn)方法解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-10-10Docker 基礎(chǔ)網(wǎng)絡(luò)配置詳解
這篇文章主要介紹了Docker 基礎(chǔ)網(wǎng)絡(luò)配置詳解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-09-09