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ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ