Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exposing a docker container to the internet

I deployed a ghost blogging platform on my server using docker. Now I want to expose it to the internet but I'm having some difficulties doing so.

I opened port 8000 in my router a forwarded it to port 32769 which is the one assign to that container. Using port 32769 inside my network I can access the website fine but when I try to access it from the internet it gives a took too long to respond error.

Local IP + PORT: http://10.0.0.140:32769/

Docker port config

Port tester

Router settings

This post was also added to Super User since it has been said that it would be responded better in there.

like image 782
DeadSec Avatar asked Mar 28 '26 06:03

DeadSec


1 Answers

Let's say your application inside docker is now working on port 8000 You want to expose your application to internet. The request would go: internet -> router -> physical computer (host machine) -> docker.

  1. You need to export your application to your host machine, this could be done via EXPOSE 8000 instruction in Dockerfile. That port should be accessible from your host machine first, so, when starting your docker image as docker container, you should add -p parameter, such as sudo docker run -d -it -p 8000:8000 --name docker_contaier_name docker_image_name From now on, your docker application can be access within your host machine, let's say it is your physical computer.
  2. Forward port from your router to your host machine This time, you may want to do as what you did in your question.
  3. Access your application from internet. If I am thinking correctly, the ip address 10.0.0.140 is just your computer LAN IP address, it cannot accessible from internet. You can only able to connect to your app via an internet IP, to do that, you can check your router to see what is your WAN IP address, which will be assigned to your router by your internet service provider. Or go google with "what is my IP"
like image 94
VinhNT Avatar answered Mar 29 '26 22:03

VinhNT