-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflask.html
65 lines (58 loc) · 2.97 KB
/
flask.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!-- THIS FILE WAS GENERATED BY A SCRIPT: DO NOT EDIT IT! -->
<html>
<!-- THIS FILE WAS GENERATED BY A SCRIPT: DO NOT EDIT IT! -->
<head>
<meta charset="UTF-8">
<link href="style.css" rel="stylesheet" type="text/css"/>
<title>
Docker for Flask Applications
</title>
</head>
<body>
<div style="text-align:center">
<figure class="logo">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/4e/Docker_%28container_engine%29_logo.svg/1920px-Docker_%28container_engine%29_logo.svg.png" width="20%">
</figure>
</div>
<ul class="menu">
<li>
<a href="index.html">HOME</a>
</li>
<li>
<a href="flask.html">APPLICATIONS</a>
</li>
<li>
<a href="about.html">ABOUT</a>
</li>
</ul>
<h2>Docker for Flask Applications</h2>
<h4>Access flask server from within docker container</h4>
<p>Change the host that flask is running on to '0.0.0.0'. The localhost in the container is local only to the container, not to your computer:</p>
<p><code>flask run -h 0.0.0.0</code></p>
<p>This will bind the app to all network interfaces on the container and will be reachable by your machine</p>
<h4>Why Is LocalHost Unreachable?</h4>
<p>Docker containers are their own little self-contained networks. They have an external interface, eth0, they have an external ip address, they have routing tables, and a localhost. Localhost doesn't map to an external interface, and it's generally bad practice to try to do so.</p>
<p>Let's take a simple container as an example, I'll just run a linux container like so:</p>
<p>docker run -it ubuntu bash
Now I can check out the network details inside that container by running apt-get update && apt-get install net-tools:</p>
<pre><code>ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.2 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:ac:11:00:02 txqueuelen 0 (Ethernet)
RX packets 11286 bytes 16471897 (16.4 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3421 bytes 189224 (189.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
</code></pre>
<p><code>lo</code> is loopback, or localhost. It's a completely separate interface and is not externally facing, eth0, however, is. You can bind to it, but I wouldn't guarantee that the ip address is the same all the time.</p>
<p>So the easiest way is to bind flask to all of them.</p>
<p><code>loopback</code> is simply for the network to communicate with itself, nothing more. It doesn't need to have an externally facing component, because by design it's not intended for external communication</p>
</body>
</html>