@@ -1340,8 +1340,9 @@ CMD python manage.py runserver
1340
1340
----
1341
1341
====
1342
1342
1343
- The extra flag to add is `-v`, and it takes a similar `outside:inside` argument as `-p` did for ports.
1344
- We specify a folder or file _outside_ the container, and the path we want it to appear at _inside_ the container.
1343
+ The extra flag to add is `--mount`,
1344
+ where we specify `type=bind`, the `source` path on our machine,
1345
+ and the `target` path _inside_ the container:
1345
1346
1346
1347
[role="small-code"]
1347
1348
[subs="specialcharacters,quotes"]
@@ -1355,23 +1356,16 @@ Running migrations:
1355
1356
Applying sessions.0001_initial... OK
1356
1357
$ *docker build -t superlists . && docker run \
1357
1358
-p 8888:8888 \
1358
- -v ./src/db.sqlite3: /src/db.sqlite3 \
1359
+ --mount type=bind,source= ./src/db.sqlite3,target= /src/db.sqlite3 \
1359
1360
-it superlists*
1360
1361
----
1361
1362
1362
- ////
1363
- footgun: if you don't have db.sqlite3
1364
-
1365
- docker: Error response from daemon: error while creating mount source path '/Users/harry.percival/workspace/Book-TDD-Web-Dev-Python/source/chapter_09_docker/superlists/src/db.sqlite3': chown /Users/harry.percival/workspace/Book-TDD-Web-Dev-Python/source/chapter_09_docker/superlists/src/db.sqlite3: permission denied.
1366
- ERRO[0000] error waiting for container: context canceled
1367
-
1368
- ❯ ls src/db.sqlite3/
1369
- ////
1370
-
1363
+ TIP: The old syntax for mounts was `-v`.
1364
+ One of the advantages of the new `--mount` syntax is that it will fail hard
1365
+ if the path you're trying to mount into the container does not exist
1366
+ (it says something like `bind source path does not exist`)
1367
+ This avoids a lot of pain, ask me how I now this.
1371
1368
1372
- TIP: if you see an error saying: `django.db.utils.OperationalError`: "unable to open database file",
1373
- try stopping the container, `rm -rf src/db.sqlite3`, then re-run the migrate command
1374
- _outside_ the container, and then rebuild and run your image.
1375
1369
1376
1370
1377
1371
And we check the FTs again.
0 commit comments