How can I access the Nginx server on the Docker from my own shell

0

Hello everyone,

I set up a basic free tier t2.micro Ubuntu server 22.04. I allowed access for SSH, HTTP, and HTTPS as entry ports. I can connect seamlessly via SSH. I installed Docker by default and then downloaded the Nginx image. After that, I executed the command 'sudo docker run --rm -i -t --name webx -p 8080:80 nginx' to run the container, and it is working smoothly. My issue is that I can't access my Nginx server from my own terminal. I tried 'curl http://172.31.xx.xx:8080' in the terminal and Safari, but I get the error 'curl: (28) Failed to connect to 172.31.xx.xx port 8080 after 75019 ms: Couldn't connect to server.' I attempted with both public and private IPs, but couldn't establish a connection. On the Ubuntu server terminal, I can reach the Nginx server.

How can I access the Nginx server on the Docker from my own shell in a polite way?

Thank you,

Mustafa

hepsys
已提問 5 個月前檢視次數 302 次
2 個答案
2
已接受的答案

Hi hepsys,

You expose your nginx on 8080 port on your host machine, so you need to open port 8080 on SecurityGroup to reach it over public IP with that port using curl http://public_ip:8080/

You can also rebind docker nginx to expose on port 80 on host machine so change to "-p 80:80" then curl http://public_ip/ should work.

Thanks,

profile picture
已回答 5 個月前
profile picture
專家
已審閱 3 個月前
0

Hello Marcin,

Thank you for your great and fast answer.

It is done. I solved the problem.

Thank you,

Mustafa

hepsys
已回答 5 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南