docker安裝nginx之后無法訪問的解決
docker安裝nginx之后無法訪問
安裝完nginx 之后,容器可以正常啟動,但是在Linux 與外面瀏覽器無法訪問,但是進(jìn)入容器內(nèi)部,可以正常訪問nginx\
代碼示例
# 運(yùn)行nginx docker run --name nginx-test -p 8081:80 -d nginx # 查看容器id docker ps
查看容器內(nèi)部ip地址
docker inspect e59d18a16a78 | grep IPAddress "SecondaryIPAddresses": null, "IPAddress": "172.17.0.2", "IPAddress": "172.17.0.2",
curl 172.17.0.2 這個時候直接就鏈接不上
進(jìn)入容器內(nèi)部可以正常訪問
[root@localhost vmuser]# docker exec -it e59d18a16a78 bash root@e59d18a16a78:/# curl 127.0.0.1 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a rel="external nofollow" >nginx.org</a>.<br/> Commercial support is available at <a rel="external nofollow" >nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
解決方案
1.查看是否關(guān)閉防火墻
systemctl status firewald.service
2.查看是否有暴漏ip地址
- 1)lsof -i :8080 查看8080端口被哪個進(jìn)程占用
- 2)netstat -lnp|grep 8080 查看8080端口被哪個進(jìn)程占用
- 3)ss -nlap | grep 8080 查看8080端口被哪個進(jìn)程占用
3.有可能是linux 版本與docker 版本不兼容(此方法解決)
# uname -a # lsb_release -a Distributor ID: CentOS Description: CentOS Linux release 7.2.1511 (Core) Release: 7.2.1511 # docker version Client: Docker Engine - Community Version: 20.10.17
升級版本內(nèi)核
#升級linux內(nèi)核版本,升級所有包同時也升級軟件和系統(tǒng)內(nèi)核 [root@localhost ~]# yum update -y
總結(jié)
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Docker通過容器生成鏡像提交DockerCommit詳解
這篇文章主要介紹了Docker通過容器生成鏡像提交DockerCommit的詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪2021-09-09三分鐘完成 ubuntu16.04初始化,Java,maven,docker環(huán)境的部署問題
這篇文章主要介紹了三分鐘完成 ubuntu16.04初始化,Java,maven,docker環(huán)境的部署問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧2020-11-11docker下遷移elasticsearch問題以及解決方案
文章描述了如何將Elasticsearch數(shù)據(jù)從一個服務(wù)器遷移到另一個服務(wù)器,包括數(shù)據(jù)掛載、版本一致性、啟動命令的匹配以及可能遇到的權(quán)限和節(jié)點(diǎn)故障問題的解決方法2024-11-11通過Docker?Compose部署MySQL的詳細(xì)教程
Docker?Compose?作為?Docker?官方的容器編排工具,為?MySQL?數(shù)據(jù)庫部署帶來了顯著優(yōu)勢,下面小編就來為大家詳細(xì)介紹一下具體的流程吧2025-03-03