建立 Docker nginx 但瀏覽器傳回網站未找到錯誤

建立 Docker nginx 但瀏覽器傳回網站未找到錯誤

Windows 11 專業版

我正在關注 Hashicorp Terraform Docker 教程:

$ docker run --name hashicorp-learn --detach --publish 8080:80 nginx:latest
dc26543abdf895e638e4c5fcb968a9ce317c57e945060e97afe03b3991646682

$ docker ps --filter="name=hashicorp-learn"
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                  NAMES
dc26543abdf8   nginx:latest   "/docker-entrypoint.…"   28 seconds ago   Up 27 seconds   0.0.0.0:8080->80/tcp   hashicorp-learn

一切看起來都很好,但是當我打開瀏覽器並轉到

http://0.0.0.0:8080 

我收到錯誤

This site can’t be reached
The webpage at http://0.0.0.0:8080/ might be temporarily down or it may have moved permanently to a new web address.
ERR_ADDRESS_INVALID

我已經在 Chrome、Firefox、Edge 中嘗試過此操作並收到類似的錯誤。

我嘗試關閉內部/外部 Windows Defender 防火牆,但仍然收到錯誤。

答案1

您在 docker ps 輸出中看到的 0.0.0.0:8080 並不表示您應該瀏覽到此位址,這表示您的伺服器正在連接埠 8080 上偵聽其所有 IP 位址,因此您應該前往

http://server_ip:8080

或者你可以透過運行在你的 docker 伺服器上測試它

curl http://127.0.0.1:8080

相關內容