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
demandé il y a 4 mois297 vues
2 réponses
2
Réponse acceptée

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
répondu il y a 4 mois
profile picture
EXPERT
vérifié il y a 2 mois
0

Hello Marcin,

Thank you for your great and fast answer.

It is done. I solved the problem.

Thank you,

Mustafa

hepsys
répondu il y a 4 mois

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions