You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// CSANAD: I'm getting a different error for some reason:
1127
-
// curl: (56) Recv failure: Connection reset by peer
1128
-
// Hopefully, just like above, the difference is irrelevantr but somebody please
1129
-
// confirm.
1139
+
NOTE: Depending on your system, instead of `(52) Empty reply from server`,
1140
+
You might see `(56) Recv failure: Connection reset by peer`.
1141
+
They mean the same thing.
1142
+
1143
+
//TODO: double-check what the difference means here.
1130
1144
1131
1145
1132
1146
==== Essential Googling the Error Message
@@ -1321,7 +1335,11 @@ NOTE: If you don't see this error,
1321
1335
and you should be able to reproduce the error. I promise it's instructive!
1322
1336
1323
1337
1324
-
==== Should we run "migrate" inside the Dockerfile? No. // JAN: Not sure I understand this line. You're saying that we shouldn't run migrate inside our Dockerfile, but then in the next line you do exactly that
1338
+
==== Should we run "migrate" inside the Dockerfile? No.
1339
+
1340
+
// JAN: Not sure I understand this line.
1341
+
// You're saying that we shouldn't run migrate inside our Dockerfile,
1342
+
// but then in the next line you do exactly that
1325
1343
1326
1344
So, should we include `manage.py migrate` in our Dockerfile?
1327
1345
@@ -1361,10 +1379,14 @@ Ran 3 tests in 26.965s
1361
1379
OK
1362
1380
----
1363
1381
1382
+
The problem is that this saves our database image into our system image,
1383
+
which is not what we want,
1384
+
because the system image is mean to be something fixed and stateless,
1385
+
whereas the database is living, stateful data that should change over time.
1386
+
1364
1387
1365
1388
=== Mounting files inside the container.
1366
1389
1367
-
But we don't actually want to package up our database _inside_ the image, do we?
1368
1390
We want the database on the server to have totally separate data from the one on our machine.
1369
1391
// CSANAD: we need to list `src/db.sqlite3` in the .dockerignore file to achieve this.
1370
1392
// Otherwise, if the reader did not delete the DB, it would still end up built into
@@ -1390,15 +1412,18 @@ First let's revert our change:
1390
1412
[source,dockerfile]
1391
1413
----
1392
1414
[...]
1415
+
COPY src /src
1416
+
1393
1417
WORKDIR /src
1394
1418
1395
1419
CMD python manage.py runserver 0.0.0.0:8888
1396
1420
----
1397
1421
====
1398
1422
1399
1423
1400
-
Let's start by re-creating the database with `migrate`
1401
-
(when we moved everything into `./src`, we left the database file behind):
1424
+
Then let's make sure we _do_ have the database on our own machine,
1425
+
by running `migrate`:
1426
+
(when we moved everything into `./src`, we left the database file behind).
1402
1427
1403
1428
[subs="specialcharacters,quotes"]
1404
1429
----
@@ -1411,14 +1436,18 @@ Running migrations:
1411
1436
Applying sessions.0001_initial... OK
1412
1437
----
1413
1438
1414
-
Let's make sure to .gitignore the new location of the DB file:
1439
+
Let's make sure to _.gitignore_ the new location of the DB file,
1440
+
and we'll also use a file called https://docs.docker.com/reference/dockerfile/#dockerignore-file[_.dockerignore_]
1441
+
to make sure we can't copy our local dev database into our Docker image
1442
+
during Docker builds:
1415
1443
1416
1444
[subs="specialcharacters,quotes"]
1417
1445
----
1418
1446
$ *echo src/db.sqlite3 >> .gitignore*
1447
+
$ *echo src/db.sqlite3 >> .dockerignore*
1419
1448
----
1420
1449
1421
-
Now let's try mounting our database file.
1450
+
Now we can rebuild and try mounting our database file.
1422
1451
The extra flag to add to the Docker run command is `--mount`,
1423
1452
where we specify `type=bind`, the `source` path on our machine,
1424
1453
and the `target` path _inside_ the container:
@@ -1455,17 +1484,18 @@ Ran 3 tests in 26.965s
1455
1484
OK
1456
1485
----
1457
1486
1458
-
//RITA: I'd rather add exclamation marks than extend the word.
1459
1487
AMAZING IT ACTUALLY WORKSSSSSSSS.
1488
+
//RITA: I'd rather add exclamation marks than extend the word.
1460
1489
1461
1490
Ahem, that's definitely good enough for now! Let's commit.
1462
1491
1463
1492
1464
1493
[subs="specialcharacters,quotes"]
1465
1494
----
1466
-
$ *git add Dockerfile*
1467
-
$ *git commit -m"First cut of a Dockerfile"*
1495
+
$ *git add -A .* # add Dockerfile, .dockerignore, .gitignore
1496
+
$ *git commit -am"First cut of a Dockerfile"*
1468
1497
----
1498
+
1469
1499
// DAVID: This is the second cut really?
1470
1500
1471
1501
Phew. Well, it took a bit of hacking about,
@@ -1478,9 +1508,8 @@ or running on port 8888 forever.
1478
1508
In the next chapter, we'll make our hacky image more production-ready.
1479
1509
1480
1510
But first, time for a well-earned tea break I think, and perhaps a
0 commit comments