How can I connect to a locally hosted site within a docker container?

Question:

I’m trying to connect to a docker container’s locally hosted address. I’m using Django to serve a website within the container, and I want to connect to it on my local machine. this is the info i get from django from within the container.

How can I access this site from my local machine?

I’ve tried to inspect the container and found that the local IP address is 172.28.0.4. Even after specifying the correct port on my browser, it still won’t connect.this is what i see.

The port 8000 is exposed in the container already, and added to the list of ports in the compose file.

What can I do to fix this issue?

Asked By: maxsptz

||

Answers:

If you can connect to the docker instance through ssh, try:

ssh [email protected] -L 8000:172.28.0.4:8000

Then navigate to your project and do py manage.py runserver 0.0.0.0:8000

Then on your local machine go to your browser and you should be able to access your app @ http://127.0.0.1:8000

Answered By: Sogetsue