How to expose Docker terminal to the internet? - python

I am creating an online IDE for different languages. So my approach to the same is to spin up a docker container from my DJango app once a user runs his code, but the problem is how do I expose the terminal of the docker container to the internet and make it accessible via the browser? I am planning to use xterm.js for the frontend of the terminal but am unable to connect to it.
Any form of insight is appreciable.

You can you an reverse-proxy with NGINX to point to your localIP:<container_port>, and then modify with your domain name.
As this exemple below:
location /some/path/ {
proxy_pass http://www.example.com/link/;
}
Adding some links to help you.
enter link description here
Also you can use 'Nginx Proxy Manager'

Short answer:
Your application uses a port to access it (for example, you use 127.0.0.1:8080 or 192.168.1.100:3000).
127.0.0.1 means the computer you are using right now, 192.168.1.100 is a computer inside the 192.168.1.0 network. (Your LAN)
You must create (on your router) access from the internet to your application.
For exemple, if your public IP address is 123.245.123.245, you need to use an external port (ex: 80), and map it to your internal address and port (ex: 192.168.1.100:3000)
the URL 123.245.123.245:80 will redirect to the website on 192.168.1.100:3000.
On the short term, this is the easiest solution.
For the long term, you should try using a Reverse Proxy.
It's a program that will (depending on the domain) redirect to sites inside your network and adding encryption in the requests (if possible).
Check this link : doc

Related

Acess a local web server from my phone using python

I'm developing for web and I have a prototype of my website. For testing locally I usually do
python3 -m http.server
and then go to localhost:8000 on my browser. This works great!
Then I read on the internet I could figure my private IPv4 IP address (10.0.0.101 as per ipconfig) and run
10.0.0.101:8000
on my phone's browser to access my website.
Thing is when I do this I get an "This site can't be reached (ERR_CONNECTION_TIMED_OUT)".
My network config
Between my ISP modem and my devices I have an router (D-Link DIR-815). An ethernet cable connects the router to my desktop computer and my phone is connected via Wi-Fi.
What I've tried
I've tried all items below and a lot of combinations between them (but unlikely all of the combinations because there are too many)
Using chrome inside the Bluestacks emulator
Forwarding the port 8000 on my router and using <my_public_ip>:8000
adding a firewall exception for the 8000 port (both TCP and UDP)
using 10.0.0.101:8000 on my desktop browser
I did it just for testing and it came as a surprise for me that this
didn't work!
using 127.0.0.1:8000 on my desktop browser (just for testing)
That didn't work. Which came as an even bigger surprise for me.
The Question
What am I missing here? Why can't I access my localhost from my phone?
I've read many question including this one which contains many answer and was the top result on google. Bug the thing is both for the sake of simplicity of using only python and for my education I want to know how can I do this without installing more complex solutions like XAMPP.
PS:
Also I know it is possible because it is shown in this video.
I double checked my private IPv4 IP in my router (dlinkrouter.local)

Locally hosted Django project for long-term use in local network

I am currently implementing a Django web application, which will be used only locally but long-term. I already managed to start the Django server on my local machine using python manage 0.0.0.0:myport and I am able to connect from any mobile device using MyLocalIPv4:myport.
In best case I only want to start the Django server once, establish a connection between a mobile device and the web app and let the web app run for an undefined long time on that mobile device
Now my assumption is, that MyLocalIPv4 will be changing over time as it is a dynamic IP address, which will force the user (or even worse myself) to look up the new IP address and re-establish the connection.
My question are: Do you know any mechanisms on how I can avoid this type of behaviour using another (maybe static) referral to the web app ? What do you think about this web application in term of security issues ?
DNS is the way to go. What you want is a (internal) domain that would map to your computer IP address.
There are many ways you can achieve that but I suggest going with whatever tools you have available. I assume that for your home network you're using some sort of a consumer-grade home router with wireless access point. Very often this type of hardware offers some way to "map" the hostname of a machine to its internal-network IP address.
For example, at home I'm using a RT-AC1200G+ router, which runs an internal DNS server and maps hostnames of clients of my network to their IP:
$ dig +short #192.168.1.2 samu-pc
192.168.1.70
$ ifconfig |grep 192.168.1.70
inet 192.168.1.70 netmask 255.255.255.0 broadcast 192.168.1.255
Alternatively, one of the easier solutions would be to ensure your IP does not change. You could assign a static IP to your django-server machine, OR if you want to continue using DHCP - use your routers functions to make a static assignment to a specific, static IP address using your network card's MAC address.
Disclaimer: There are other, more "professional" ways of solving service discovery within a network, but I would consider them overkill to your home network setup. Also, if you care about security, you should consider running the django app behind a reverse proxy with HTTPs on the front, just to ensure nobody in your internal network is trying to do something nasty.

Access django main page by its name not ip

is there a way to configure a Django server in that way so I can open my local webpage by typing 'weatherstation.local' and not by the IP:port?
in your router you might be able to set DNS. if DNS administration exists, then here you can set different domain names for IP addresses on your network.
You can give your ip address multiple domain names, and then you can use somthing like NGINX to route the domain calls to different services that you are running on your server.
Good luck, I hope this was helpful ;-)

How do I point my reserved domain to a Django EC2 instance?

Ok so I'm hosting a Django EC2 instance right now using ngrok http 8000 and leaving it running. It's doing fine but a lot of browsers are blocking the traffic to my site. I need to make my reserved domain (I have some on Amazon and some on 1 and 1) to my 123.4.5.67:8000 public IPv4 IP or just my public IPv4 DNS on my EC2.
What I need in a nutshell is example.com to redirect to 123.4.5.67:8000 while still saying example.com in the url.
So far I have heard of Apache, WSGI, and nginx. None of them have worked for me, but maybe I haven't gotten the right direction.
Please help!
I’m pretty sure that you need to make this change wherever you host your domain. The only way i was able to do this with my personal server was to point to port 80instead of 8000

Redirecting traffic to other webserver

Here is my setup: I have a Python webserver (written myself) that listens on port 80 and also have the Transmission-daemon (bittorrent client) that provides a webUI on port 9101. (running on Linux)
I can access both webservers locally without problems, but now would like to access them externally also. My issue is that I would prefer not to have to open extra ports on my firewall to access the Transmission webUI. Is it possible to within the python webserver to redirect some traffic to the appropriate port.
So for example:
http: //mywebserver/index.html -> served by the Python webserver
http: //mywebserver/transmission.html -> redirected to transmission (which is currently http: //localhost:9101)
Thanks
I found my answer: a reverse proxy. It will take care of the routing to the correct port based on the URL. I now just have to select the right one there are so many (NginX, pound, lighttd etc...)
Thanks anyway.
Return an http response with status code 300, see this

Categories