Jimmy Allen 2 månader sedan
förälder
incheckning
8eb483dbac
4 ändrade filer med 89 tillägg och 121 borttagningar
  1. 1 0
      .env
  2. 47 121
      docker.ipynb
  3. 5 0
      webserver/Dockerfile
  4. 36 0
      webserver/server.py

+ 1 - 0
.env

@@ -0,0 +1 @@
1
+COMPOSE_CONVERT_WINDOWS_PATHS=1

+ 47 - 121
docker.ipynb

@@ -9,20 +9,17 @@
9 9
   },
10 10
   {
11 11
    "cell_type": "code",
12
-   "execution_count": 1,
13
-   "metadata": {
14
-    "slideshow": {
15
-     "slide_type": "slide"
16
-    }
17
-   },
12
+   "execution_count": null,
13
+   "metadata": {},
18 14
    "outputs": [],
19 15
    "source": [
20
-    "import docker"
16
+    "%run cleanup.py\n",
17
+    "%run monitor.py"
21 18
    ]
22 19
   },
23 20
   {
24 21
    "cell_type": "code",
25
-   "execution_count": 2,
22
+   "execution_count": null,
26 23
    "metadata": {
27 24
     "slideshow": {
28 25
      "slide_type": "slide"
@@ -30,69 +27,53 @@
30 27
    },
31 28
    "outputs": [],
32 29
    "source": [
30
+    "import docker\n",
33 31
     "client = docker.from_env()"
34 32
    ]
35 33
   },
36 34
   {
37
-   "cell_type": "code",
38
-   "execution_count": 3,
35
+   "cell_type": "markdown",
39 36
    "metadata": {},
40
-   "outputs": [],
41 37
    "source": [
42
-    "%run monitor.py"
38
+    "### Start a container"
43 39
    ]
44 40
   },
45 41
   {
46 42
    "cell_type": "code",
47
-   "execution_count": 4,
43
+   "execution_count": null,
48 44
    "metadata": {},
49
-   "outputs": [
50
-    {
51
-     "name": "stdout",
52
-     "output_type": "stream",
53
-     "text": [
54
-      "\u001b[32mMonitor: A container has been created\n",
55
-      "\u001b[92mMonitor: A container has been started\n",
56
-      "\u001b[91mMonitor: A container has been stopped\n"
57
-     ]
58
-    },
59
-    {
60
-     "data": {
61
-      "text/plain": [
62
-       "b''"
63
-      ]
64
-     },
65
-     "execution_count": 4,
66
-     "metadata": {},
67
-     "output_type": "execute_result"
68
-    }
69
-   ],
45
+   "outputs": [],
70 46
    "source": [
71 47
     "client.containers.run(image=\"ubuntu\", name=\"ubuntu\")"
72 48
    ]
73 49
   },
74 50
   {
51
+   "cell_type": "markdown",
52
+   "metadata": {},
53
+   "source": [
54
+    "### List all containers"
55
+   ]
56
+  },
57
+  {
75 58
    "cell_type": "code",
76
-   "execution_count": 5,
59
+   "execution_count": null,
77 60
    "metadata": {},
78
-   "outputs": [
79
-    {
80
-     "name": "stdout",
81
-     "output_type": "stream",
82
-     "text": [
83
-      "ubuntu\n",
84
-      "jupyter_jupyter_1\n"
85
-     ]
86
-    }
87
-   ],
61
+   "outputs": [],
88 62
    "source": [
89 63
     "for container in client.containers.list(all=True):\n",
90 64
     "    print(container.name)"
91 65
    ]
92 66
   },
93 67
   {
68
+   "cell_type": "markdown",
69
+   "metadata": {},
70
+   "source": [
71
+    "### Get a container"
72
+   ]
73
+  },
74
+  {
94 75
    "cell_type": "code",
95
-   "execution_count": 6,
76
+   "execution_count": null,
96 77
    "metadata": {},
97 78
    "outputs": [],
98 79
    "source": [
@@ -101,68 +82,41 @@
101 82
   },
102 83
   {
103 84
    "cell_type": "code",
104
-   "execution_count": 7,
85
+   "execution_count": null,
105 86
    "metadata": {},
106
-   "outputs": [
107
-    {
108
-     "name": "stdout",
109
-     "output_type": "stream",
110
-     "text": [
111
-      "exited\n"
112
-     ]
113
-    }
114
-   ],
87
+   "outputs": [],
115 88
    "source": [
116 89
     "print(ubuntu.status)"
117 90
    ]
118 91
   },
119 92
   {
93
+   "cell_type": "markdown",
94
+   "metadata": {},
95
+   "source": [
96
+    "### Start a container"
97
+   ]
98
+  },
99
+  {
120 100
    "cell_type": "code",
121
-   "execution_count": 8,
101
+   "execution_count": null,
122 102
    "metadata": {},
123
-   "outputs": [
124
-    {
125
-     "name": "stdout",
126
-     "output_type": "stream",
127
-     "text": [
128
-      "\u001b[92mMonitor: A container has been started\n"
129
-     ]
130
-    }
131
-   ],
103
+   "outputs": [],
132 104
    "source": [
133 105
     "ubuntu.start()"
134 106
    ]
135 107
   },
136 108
   {
137 109
    "cell_type": "code",
138
-   "execution_count": 9,
110
+   "execution_count": null,
139 111
    "metadata": {},
140
-   "outputs": [
141
-    {
142
-     "name": "stdout",
143
-     "output_type": "stream",
144
-     "text": [
145
-      "\u001b[91mMonitor: A container has been stopped\n"
146
-     ]
147
-    },
148
-    {
149
-     "data": {
150
-      "text/plain": [
151
-       "{'Error': None, 'StatusCode': 0}"
152
-      ]
153
-     },
154
-     "execution_count": 9,
155
-     "metadata": {},
156
-     "output_type": "execute_result"
157
-    }
158
-   ],
112
+   "outputs": [],
159 113
    "source": [
160 114
     "ubuntu.wait()"
161 115
    ]
162 116
   },
163 117
   {
164 118
    "cell_type": "code",
165
-   "execution_count": 10,
119
+   "execution_count": null,
166 120
    "metadata": {},
167 121
    "outputs": [],
168 122
    "source": [
@@ -171,34 +125,18 @@
171 125
   },
172 126
   {
173 127
    "cell_type": "code",
174
-   "execution_count": 11,
128
+   "execution_count": null,
175 129
    "metadata": {},
176
-   "outputs": [
177
-    {
178
-     "name": "stdout",
179
-     "output_type": "stream",
180
-     "text": [
181
-      "\u001b[31mMonitor: A container has been deleted\n"
182
-     ]
183
-    }
184
-   ],
130
+   "outputs": [],
185 131
    "source": [
186 132
     "ubuntu.remove()"
187 133
    ]
188 134
   },
189 135
   {
190 136
    "cell_type": "code",
191
-   "execution_count": 12,
137
+   "execution_count": null,
192 138
    "metadata": {},
193
-   "outputs": [
194
-    {
195
-     "name": "stdout",
196
-     "output_type": "stream",
197
-     "text": [
198
-      "jupyter_jupyter_1\n"
199
-     ]
200
-    }
201
-   ],
139
+   "outputs": [],
202 140
    "source": [
203 141
     "for container in client.containers.list(all=True):\n",
204 142
     "    print(container.name)"
@@ -234,21 +172,9 @@
234 172
   },
235 173
   {
236 174
    "cell_type": "code",
237
-   "execution_count": 14,
175
+   "execution_count": null,
238 176
    "metadata": {},
239
-   "outputs": [
240
-    {
241
-     "ename": "NameError",
242
-     "evalue": "name 'monitor' is not defined",
243
-     "output_type": "error",
244
-     "traceback": [
245
-      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
246
-      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
247
-      "\u001b[0;32m<ipython-input-14-804e8a6962d2>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmonitor\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstop\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
248
-      "\u001b[0;31mNameError\u001b[0m: name 'monitor' is not defined"
249
-     ]
250
-    }
251
-   ],
177
+   "outputs": [],
252 178
    "source": [
253 179
     "monitor.t.stop()"
254 180
    ]

+ 5 - 0
webserver/Dockerfile

@@ -0,0 +1,5 @@
1
+FROM python:3
2
+
3
+COPY server.py /server.py
4
+
5
+ENTRYPOINT [ "python", "server.py" ]

+ 36 - 0
webserver/server.py

@@ -0,0 +1,36 @@
1
+from http.server import BaseHTTPRequestHandler
2
+import json
3
+
4
+
5
+class GetHandler(BaseHTTPRequestHandler):
6
+    def do_GET(self):
7
+
8
+        message = "Hello"
9
+        print(self.path)
10
+        self.send_response(200)
11
+        self.end_headers()
12
+        self.wfile.write(bytes(message, "utf8"))
13
+        return
14
+
15
+    def do_POST(self):
16
+        content_len = int(self.headers.getheader("content-length"))
17
+        post_body = self.rfile.read(content_len)
18
+        self.send_response(200)
19
+        self.end_headers()
20
+
21
+        data = json.loads(post_body)
22
+
23
+        self.wfile.write(data["foo"])
24
+        return
25
+
26
+
27
+if __name__ == "__main__":
28
+    from http.server import HTTPServer
29
+    import ssl
30
+
31
+    server = HTTPServer(("0.0.0.0", 8080), GetHandler)
32
+    """server.socket = ssl.wrap_socket(
33
+        server.socket, certfile="ssl/cert.pem", server_side=True
34
+    )"""
35
+    print("Starting server at https://localhost:8080")
36
+    server.serve_forever()