Skip to content

Commit 62b824e

Browse files
authored
Merge pull request SensorsIot#535 from Paraphraser/20220327-python-doco-master
20220327 Python documentation
2 parents d57d34a + e78bc95 commit 62b824e

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

docs/Containers/Python.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Python
22

3-
## references
3+
## <a name="references"></a>references
44

55
* [Python.org](https://www.python.org)
66
* [Dockerhub image library](https://hub.docker.com/_/python)
77
* [GitHub docker-library/python](https://github.com/docker-library/python)
88

9-
## selecting Python in the IOTstack menu
9+
## <a name="menuPython"></a>selecting Python in the IOTstack menu
1010

1111
When you select Python in the menu:
1212

@@ -42,7 +42,7 @@ When you select Python in the menu:
4242
- ./volumes/python/app:/usr/src/app
4343
```
4444

45-
### customising your Python service definition
45+
### <a name="customisingPython"></a>customising your Python service definition
4646

4747
The service definition contains a number of customisation points:
4848

@@ -70,7 +70,7 @@ $ cd ~/IOTstack
7070
$ docker-compose up -d python
7171
```
7272

73-
## Python - first launch
73+
## <a name="firstLaunchPython"></a>Python - first launch
7474

7575
After running the menu, you are told to run the commands:
7676

@@ -139,7 +139,7 @@ This is what happens:
139139

140140
Pressing <kbd>control</kbd>+<kbd>c</kbd> terminates the log display but does not terminate the running container.
141141

142-
## stopping the Python service
142+
## <a name="stopPython"></a>stopping the Python service
143143

144144
To stop the container from running, either:
145145

@@ -157,7 +157,7 @@ To stop the container from running, either:
157157
$ docker-compose rm --force --stop -v python
158158
```
159159

160-
## starting the Python service
160+
## <a name="startPython"></a>starting the Python service
161161

162162
To bring up the container again after you have stopped it, either:
163163

@@ -175,23 +175,23 @@ To bring up the container again after you have stopped it, either:
175175
$ docker-compose up -d python
176176
```
177177

178-
## Python - second-and-subsequent launch
178+
## <a name="reLaunchPython"></a>Python - second-and-subsequent launch
179179

180180
Each time you launch the Python container *after* the first launch:
181181

182182
1. The existing local image (`iotstack_python`) is instantiated to become the running container.
183183
2. The `docker-entrypoint.sh` script runs and performs "self-repair" by replacing any files that have gone missing from the persistent storage area. Self-repair does **not** overwrite existing files!
184184
3. The `app.py` Python script is run.
185185

186-
## when things go wrong - check the log
186+
## <a name="debugging"></a>when things go wrong - check the log
187187

188188
If the container misbehaves, the log is your friend:
189189

190190
``` console
191191
$ docker logs python
192192
```
193193

194-
## project development life-cycle
194+
## <a name="yourPythonScript"></a>project development life-cycle
195195

196196
It is **critical** that you understand that **all** of your project development should occur within the folder:
197197

@@ -201,7 +201,7 @@ It is **critical** that you understand that **all** of your project development
201201

202202
So long as you are performing some sort of routine backup (either with a supplied script or a third party solution like [Paraphraser/IOTstackBackup](https://github.com/Paraphraser/IOTstackBackup)), your work will be protected.
203203

204-
### getting started
204+
### <a name="gettingStarted"></a>getting started
205205

206206
Start by editing the file:
207207

@@ -222,7 +222,7 @@ $ cd ~/IOTstack
222222
$ docker-compose restart python
223223
```
224224

225-
### reading and writing to disk
225+
### <a name="persistentStorage"></a>reading and writing to disk
226226

227227
Consider this line in the service definition:
228228

@@ -249,7 +249,7 @@ What it means is that:
249249

250250
If your script writes into any other directory inside the container, the data will be lost when the container re-launches.
251251

252-
### getting a clean slate
252+
### <a name="cleanSlate"></a>getting a clean slate
253253

254254
If you make a mess of things and need to start from a clean slate, erase the persistent storage area:
255255

@@ -262,7 +262,7 @@ $ docker-compose up -d python
262262

263263
The container will re-initialise the persistent storage area from its defaults.
264264

265-
### adding packages
265+
### <a name="addingPackages"></a>adding packages
266266

267267
As you develop your project, you may find that you need to add supporting packages. For this example, we will assume you want to add "[Flask](https://pypi.org/project/Flask/)" and "[beautifulsoup4](https://pypi.org/project/beautifulsoup4/)".
268268

@@ -316,7 +316,7 @@ To make *Flask* and *beautifulsoup4* a permanent part of your container:
316316
Flask==2.0.1
317317
```
318318

319-
5. Continue your development work by returning to [getting started](#getting-started).
319+
5. Continue your development work by returning to [getting started](#gettingStarted).
320320

321321
Note:
322322

@@ -340,11 +340,11 @@ Note:
340340

341341
The `requirements.txt` file will be recreated and it will be a copy of the version in the *services* directory as of the last image rebuild.
342342

343-
### making your own Python script the default
343+
### <a name="scriptBaking"></a>making your own Python script the default
344344

345-
Suppose the Python script you have been developing reaches a major milestone and you decide to "freeze dry" your work up to that point so that it becomes the default when you ask for a [clean slate](#getting-a-clean-slate). Proceed like this:
345+
Suppose the Python script you have been developing reaches a major milestone and you decide to "freeze dry" your work up to that point so that it becomes the default when you ask for a [clean slate](#cleanSlate). Proceed like this:
346346

347-
1. If you have added any packages by following the steps in [adding packages](#adding-packages), run the following command:
347+
1. If you have added any packages by following the steps in [adding packages](#addingPackages), run the following command:
348348

349349
``` console
350350
$ docker exec python bash -c 'pip3 freeze >requirements.txt'
@@ -406,11 +406,11 @@ Suppose the Python script you have been developing reaches a major milestone and
406406
$ docker system prune -f
407407
```
408408

409-
### canning your project
409+
### <a name="scriptCanning"></a>canning your project
410410

411411
Suppose your project has reached the stage where you wish to put it into production as a service under its own name. Make two further assumptions:
412412

413-
1. You have gone through the steps in [making your own Python script the default](#making-your-own-python-script-the-default) and you are **certain** that the content of `./services/python/app` correctly captures your project.
413+
1. You have gone through the steps in [making your own Python script the default](#scriptBaking) and you are **certain** that the content of `./services/python/app` correctly captures your project.
414414
2. You want to give your project the name "wishbone".
415415

416416
Proceed like this:
@@ -471,7 +471,7 @@ Remember:
471471
~/IOTstack/volumes/wishbone/app
472472
```
473473

474-
## routine maintenance
474+
## <a name="routineMaintenance"></a>routine maintenance
475475

476476
To make sure you are running from the most-recent **base** image of Python from Dockerhub:
477477

@@ -495,4 +495,4 @@ The old base image can't be removed until the old local image has been removed,
495495

496496
Note:
497497

498-
* If you have followed the steps in [canning your project](#canning-your-project) and your service has a name other than `python`, just substitute the new name where you see `python` in the two `dockerc-compose` commands.
498+
* If you have followed the steps in [canning your project](#scriptCanning) and your service has a name other than `python`, just substitute the new name where you see `python` in the two `dockerc-compose` commands.

0 commit comments

Comments
 (0)