Skip to content

Commit 9f19454

Browse files
authored
Merge pull request #212 from seddonym/review-docker
Review Docker chapter
2 parents 508759e + ee2ef5f commit 9f19454

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

chapter_09_docker.asciidoc

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,11 @@ and where testing fits in.
301301
* Get a first cut of our code up and running inside Docker,
302302
with passing tests.
303303

304+
// DAVID: might be worth condensing this bulleted list, it's rather skimmable
305+
// at the moment. For example is there any difference between the first and fourth point?
304306

305307
//RITA: Consider cross-referencing the chapter by number here so we can hyperlink it for convenience.
308+
306309
**Next chapter: Moving to a production-ready configuration**
307310

308311
* Gradually, incrementally change the container configuration
@@ -360,7 +363,7 @@ class NewVisitorTest(StaticLiveServerTestCase):
360363
self.live_server_url = "http://" + test_server #<2>
361364
----
362365
====
363-
366+
// DAVID: could use a walrus operator here?
364367

365368
Do you remember I said that `LiveServerTestCase` had certain limitations?
366369
Well, one is that it always assumes you want to use its own test server,
@@ -459,17 +462,21 @@ TIP: Don't use `export` to set the 'TEST_SERVER' environment variable;
459462

460463
==== Making an src Folder
461464

465+
// DAVID: FWIW it reads weirdly to me to have 'an src' rather than 'a src'.
466+
// It's probably because I pronounce it as 'source' rather than 'S.R.C.'
467+
462468
When preparing a codebase for deployment,
463469
it's often convenient to separate out the actual source code of our production app,
464470
from the rest of the files that you need in the project.
465471
A folder called _src_ is a common convention.
466472

473+
// DAVID: I'd expect src here and below to be in monospace.
474+
467475
Currently, all our code is source code really, so we move everything into _src_
468-
(we'll be seeing some new files appearing outside _src_ shortly.footnote:[
476+
(we'll be seeing some new files appearing outside _src_ shortly).footnote:[
469477
A common thing to find outside of the _src_ folder is a folder called _tests_.
470478
We won't be doing that while we're relying on the standard Django test framework,
471479
but it's a good thing to do if you're using pytest, for example.]
472-
)
473480

474481

475482

@@ -516,6 +523,13 @@ Cool! We'll find out more about all of these steps as the chapter progresses.
516523
Impartiality commands me to also recommend https://podman.io/[Podman],
517524
which is a like-for-like replacement for Docker.
518525
526+
// DAVID: It might be worth mentioning Colima, which I have running on my machine
527+
// instead of Docker because of licensing restrictions. I was able to run the
528+
// same command because I have Colima installed. The good thing about Colima
529+
// is you just use the same `docker` command, don't need to change it.
530+
// Also - possibly worth moving the alternatives a couple of paras further
531+
// up, so that they know their options before running the Docker install?
532+
519533
It's pretty much exactly the same as Docker,
520534
arguably with a few advantages even, but I won't go into detail here.
521535
@@ -527,7 +541,7 @@ Docker is open source too,
527541
so I decided to stick with it. But you could definitely check it out!
528542
529543
You can follow along all the instructions in the book
530-
by just substituing the `docker` binary for `podman` in all the CLI instructions,
544+
by just substituting the `docker` binary for `podman` in all the CLI instructions,
531545
e.g.
532546
533547
[role="skipme"]
@@ -550,6 +564,9 @@ including the operating system, dependencies, and any code you want to run.
550564

551565
Once you have an image, you can run one or many containers that use the same image.
552566

567+
// DAVID: Not sure whether this is going to be understandable in its current form.
568+
// An analogy that I find helpful here is that images are like classes
569+
// and containers are like instances.
553570

554571
==== A First Cut of a Dockerfile
555572

@@ -566,6 +583,11 @@ What do we need to do? Something like this, right?
566583
We create a new file called _Dockerfile_ in the base folder of our repo,
567584
next to the `src/` directory we made earlier:
568585

586+
// DAVID: As discussed, I misread this and put the Dockerfile in src.
587+
// That led to a difficult to understand error message when I tried to build.
588+
// ERROR: failed to solve: failed to compute cache key: failed to calculate
589+
// checksum of ref e126cbb4-3e0c-4e6e-867f-dbfbf5fb190f::k2oys44pcnbefrlpps3ooux7w: "/src": not found
590+
569591
// JAN: I'd suggest to use python3.11:slim or python3:12 slim. Keeping image tags too open leads to issues in a couple of months (not always, but waaay too often)
570592
// JAN: I'd use Docker comments with # for <1>, <2>, ... Otherwise, you need to edit the code when you paste it
571593

@@ -711,6 +733,9 @@ environment?
711733
----
712734
713735
736+
// DAVID: I got:
737+
// python: can't open file '/src/manage.py': [Errno 2] No such file or directory
738+
714739
Ah, we forgot that we need to install Django.
715740
716741
@@ -754,6 +779,7 @@ CMD python manage.py runserver
754779
<3> We install Django with `pip install`, just like we do locally.
755780
756781
782+
// DAVID: Why bother with a virtualenv?
757783
758784
==== Successful Run
759785
@@ -805,13 +831,16 @@ WARNING: Make sure you use the `-it` flags to the Docker `run`
805831
to interrupt the docker process with _Ctrl-C_.
806832
See <<how-to-stop-a-docker-container>> for an escape hatch.
807833
834+
// DAVID: behaviours -> behaviour?
808835
809836
[[how-to-stop-a-docker-container]]
810837
.How to Stop a Docker Container
811838
*******************************************************************************
812839
If you've got a container that's "hanging" in a terminal window,
813840
you can kill it from another one.
814841
842+
// DAVID: are we actually killing it from another container?
843+
815844
The docker daemon lets you list all the currently running containers
816845
with `docker ps`:
817846
@@ -1032,7 +1061,10 @@ $ *docker build -t superlists . && docker run -p 8888:8888 -it superlists*
10321061
Now that will _change_ the error we see, but only quite subtly (see <<firefox-connection-reset>>).
10331062
Things clearly aren't working yet.
10341063
1064+
// DAVID: FWIW in Chrome the message is "127.0.0.1 didn’t send any data."
1065+
10351066
//RITA: If at all possible, I suggest using the light or daytime theme for all browser screenshots to make them easier to read.
1067+
10361068
[[firefox-connection-reset]]
10371069
.Cannot connect on that port
10381070
image::images/firefox-connection-reset.png["Firefox showing the 'Connection reset' error"]
@@ -1107,6 +1139,9 @@ The long and short of it is that
11071139
we need use the long-form `ipaddr:port` version of the `runserver` command,
11081140
using the magic "wilcard" IP address `0.0.0.0`:
11091141
1142+
// DAVID: Some readers might not be that comfortable with the idea of ports.
1143+
// I think this could do with more explanation.
1144+
11101145
.Dockerfile (ch09l007)
11111146
====
11121147
[source,dockerfile]
@@ -1128,6 +1163,7 @@ $ *docker build -t superlists . && docker run -p 8888:8888 -it superlists*
11281163
Starting development server at http://0.0.0.0:8888/
11291164
----
11301165
1166+
11311167
We can verify it's working with `curl`:
11321168
11331169
[subs="specialcharacters,macros"]
@@ -1215,6 +1251,8 @@ we highlighted as one of the "danger areas" of deployment).
12151251
You might have spotted the yellow Django debug page (<<django-debug-screen>>)
12161252
telling us as much, or if you tried it manually.
12171253
1254+
// DAVID: Grammar on that last sentence?
1255+
12181256
NOTE: The tests saved us from potential embarrassment there.
12191257
The site _looked_ fine when we loaded its front page.
12201258
If we'd been a little hasty and only testing manually,
@@ -1234,6 +1272,8 @@ To be fair, if you look back through the `runserver` command output
12341272
each time we've been starting our container,
12351273
you'll see it's been warning us about this issue:
12361274
1275+
// DAVID: mix between 'you' and 'our' reads weirdly.
1276+
12371277
[role="skipme"]
12381278
----
12391279
You have 19 unapplied migration(s). Your project may not work properly until
@@ -1295,6 +1335,9 @@ OK
12951335
But we don't actually want to package up our database _inside_ the image, do we?
12961336
We want the database on the server to have totally separate data from the one on our machine.
12971337
1338+
// DAVID: This is an important point which might need a bit more explanation.
1339+
// What would happen if we did?
1340+
12981341
In most deployments, you'd probably be talking to a separate database server, like postgres.
12991342
13001343
For the purposes of this book, the easiest analogy to a server that's "outside" our container,
@@ -1388,7 +1431,7 @@ Ahem, that's definitely good enough for now! Let's commit.
13881431
$ *git add Dockerfile*
13891432
$ *git commit -m"First cut of a Dockerfile"*
13901433
----
1391-
1434+
// DAVID: This is the second cut really?
13921435
13931436
Phew. Well, it took a bit of hacking about,
13941437
but now we can be reassured that the basic Docker plumbing works.
@@ -1402,11 +1445,13 @@ In the next chapter, we'll make our hacky image more production-ready.
14021445
But first, time for a well-earned tea break I think, and perhaps a
14031446
https://en.wikipedia.org/wiki/Digestive_biscuit[chocolate biscuit].
14041447
1448+
// DAVID: That ain't no chocolate biscuit!
14051449
14061450
.Test-Driving Server Configuration and Deployment
14071451
*******************************************************************************
14081452
14091453
Tests and small steps some of the uncertainty out of deployment::
1454+
// DAVID: wording here?
14101455
For developers, ops and infra work is always "fun",
14111456
by which I mean a process full of fear, uncertainty and surprises.
14121457
My aim during this chapter was to show that a step-by-step approach

0 commit comments

Comments
 (0)