Bläddra i källkod

Initial Commit

Jimmy Allen 3 månader sedan
förälder
incheckning
aaf5f053bf
6 ändrade filer med 185 tillägg och 0 borttagningar
  1. 5 0
      .gitignore
  2. 22 0
      Dockerfile
  3. 0 0
      docker-compose.yml
  4. 151 0
      docker.ipynb
  5. 5 0
      entry.sh
  6. 2 0
      hello.py

+ 5 - 0
.gitignore

@@ -58,3 +58,8 @@ docs/_build/
58 58
 # PyBuilder
59 59
 target/
60 60
 
61
+#Jupyter
62
+.ipynb_checkpoints/
63
+.ipython/
64
+.jupyter/
65
+.local/

+ 22 - 0
Dockerfile

@@ -0,0 +1,22 @@
1
+FROM python:3
2
+
3
+RUN pip install \
4
+    docker \
5
+    jupyter
6
+
7
+COPY docker.ipynb /data/docker.ipynb
8
+COPY *.py /data
9
+COPY entry.sh /entry.sh
10
+
11
+RUN useradd -d /data jupyter \
12
+    && chown -R jupyter:jupyter /data
13
+
14
+
15
+
16
+EXPOSE 8888
17
+
18
+VOLUME /data
19
+
20
+WORKDIR /data
21
+
22
+ENTRYPOINT [ "/bin/bash", "/entry.sh" ]

+ 0 - 0
docker-compose.yml


+ 151 - 0
docker.ipynb

@@ -0,0 +1,151 @@
1
+{
2
+ "cells": [
3
+  {
4
+   "cell_type": "code",
5
+   "execution_count": 3,
6
+   "metadata": {
7
+    "slideshow": {
8
+     "slide_type": "slide"
9
+    }
10
+   },
11
+   "outputs": [],
12
+   "source": [
13
+    "import docker"
14
+   ]
15
+  },
16
+  {
17
+   "cell_type": "code",
18
+   "execution_count": 4,
19
+   "metadata": {
20
+    "slideshow": {
21
+     "slide_type": "slide"
22
+    }
23
+   },
24
+   "outputs": [],
25
+   "source": [
26
+    "client = docker.from_env()"
27
+   ]
28
+  },
29
+  {
30
+   "cell_type": "code",
31
+   "execution_count": null,
32
+   "metadata": {
33
+    "scrolled": true
34
+   },
35
+   "outputs": [],
36
+   "source": [
37
+    "print(client.containers.run(image=\"ubuntu\", name=\"ubuntu\"))"
38
+   ]
39
+  },
40
+  {
41
+   "cell_type": "code",
42
+   "execution_count": null,
43
+   "metadata": {},
44
+   "outputs": [],
45
+   "source": [
46
+    "client.containers.remove(\"ubuntu\")"
47
+   ]
48
+  },
49
+  {
50
+   "cell_type": "code",
51
+   "execution_count": null,
52
+   "metadata": {},
53
+   "outputs": [],
54
+   "source": [
55
+    "import threading\n",
56
+    "\n",
57
+    "def Monitor():\n",
58
+    "    for event in client.events(decode=True):\n",
59
+    "        eventType = event[\"Action\"]\n",
60
+    "        if eventType == 'start':\n",
61
+    "            print(\"Monitor: A container has been created\")\n",
62
+    "        if eventType == 'die':\n",
63
+    "            print(\"Monitor: A container has been destroyed\")\n",
64
+    "            \n",
65
+    "import threading\n",
66
+    "t = threading.Thread(target=Monitor)\n",
67
+    "t.start()"
68
+   ]
69
+  },
70
+  {
71
+   "cell_type": "code",
72
+   "execution_count": null,
73
+   "metadata": {},
74
+   "outputs": [],
75
+   "source": [
76
+    "client.containers.run(\"ubuntu\", \"echo hello world\", environment=[\"a=b\"])"
77
+   ]
78
+  },
79
+  {
80
+   "cell_type": "code",
81
+   "execution_count": 1,
82
+   "metadata": {},
83
+   "outputs": [
84
+    {
85
+     "name": "stdout",
86
+     "output_type": "stream",
87
+     "text": [
88
+      "b\n"
89
+     ]
90
+    }
91
+   ],
92
+   "source": [
93
+    "%run hello.py\n",
94
+    "import hello\n",
95
+    "hello.h(\"b\")"
96
+   ]
97
+  },
98
+  {
99
+   "cell_type": "code",
100
+   "execution_count": 5,
101
+   "metadata": {},
102
+   "outputs": [
103
+    {
104
+     "name": "stdout",
105
+     "output_type": "stream",
106
+     "text": [
107
+      "<docker.client.DockerClient object at 0x7f5e504bc8d0>\n"
108
+     ]
109
+    }
110
+   ],
111
+   "source": [
112
+    "print(client)"
113
+   ]
114
+  },
115
+  {
116
+   "cell_type": "code",
117
+   "execution_count": null,
118
+   "metadata": {},
119
+   "outputs": [],
120
+   "source": []
121
+  },
122
+  {
123
+   "cell_type": "code",
124
+   "execution_count": null,
125
+   "metadata": {},
126
+   "outputs": [],
127
+   "source": []
128
+  }
129
+ ],
130
+ "metadata": {
131
+  "kernelspec": {
132
+   "display_name": "Python 3",
133
+   "language": "python",
134
+   "name": "python3"
135
+  },
136
+  "language_info": {
137
+   "codemirror_mode": {
138
+    "name": "ipython",
139
+    "version": 3
140
+   },
141
+   "file_extension": ".py",
142
+   "mimetype": "text/x-python",
143
+   "name": "python",
144
+   "nbconvert_exporter": "python",
145
+   "pygments_lexer": "ipython3",
146
+   "version": "3.7.0"
147
+  }
148
+ },
149
+ "nbformat": 4,
150
+ "nbformat_minor": 2
151
+}

+ 5 - 0
entry.sh

@@ -0,0 +1,5 @@
1
+#!/bin/bash
2
+
3
+chown jupyter /var/run/docker.sock 
4
+
5
+su - jupyter -c "/usr/local/bin/jupyter notebook --ip=0.0.0.0 --NotebookApp.token=''"

+ 2 - 0
hello.py

@@ -0,0 +1,2 @@
1
+def h(h):
2
+    print(h)