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
asked 4 months ago267 views
2 Answers
2
Accepted Answer

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
answered 4 months ago
profile picture
EXPERT
reviewed 2 months ago
0

Hello Marcin,

Thank you for your great and fast answer.

It is done. I solved the problem.

Thank you,

Mustafa

hepsys
answered 4 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions