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 个月前303 查看次数
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 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则