Skip to content

Commit 382ec1b

Browse files
committed
switch to --mount syntax for bind mounts
1 parent a0ea1ce commit 382ec1b

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

chapter_09_docker.asciidoc

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,8 +1340,9 @@ CMD python manage.py runserver
13401340
----
13411341
====
13421342

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:
13451346

13461347
[role="small-code"]
13471348
[subs="specialcharacters,quotes"]
@@ -1355,23 +1356,16 @@ Running migrations:
13551356
Applying sessions.0001_initial... OK
13561357
$ *docker build -t superlists . && docker run \
13571358
-p 8888:8888 \
1358-
-v ./src/db.sqlite3:/src/db.sqlite3 \
1359+
--mount type=bind,source=./src/db.sqlite3,target=/src/db.sqlite3 \
13591360
-it superlists*
13601361
----
13611362

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.
13711368

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.
13751369

13761370

13771371
And we check the FTs again.

chapter_10_production_readiness.asciidoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pattern to try out our changes by rebuilding and rerunning our container:
9191
----
9292
$ *docker build -t superlists . && docker run \
9393
-p 8888:8888 \
94-
-v ./src/db.sqlite3:/src/db.sqlite3 \
94+
--mount type=bind,source=./src/db.sqlite3,target=/src/db.sqlite3 \
9595
-it superlists*
9696
----
9797

@@ -290,7 +290,7 @@ And try it out...
290290
----
291291
$ pass:specialcharacters,quotes[*docker build -t superlists . && docker run \
292292
-p 8888:8888 \
293-
-v ./src/db.sqlite3:/src/db.sqlite3 \
293+
--mount type=bind,source=./src/db.sqlite3,target=/src/db.sqlite3 \
294294
-it superlists*]
295295
296296
[...]
@@ -316,7 +316,7 @@ For now, we can set it at the command line using the `-e` flag for `docker run`:
316316
----
317317
$ *docker build -t superlists . && docker run \
318318
-p 8888:8888 \
319-
-v ./src/db.sqlite3:/src/db.sqlite3 \
319+
--mount type=bind,source=./src/db.sqlite3,target=/src/db.sqlite3 \
320320
-e DJANGO_SECRET_KEY=sekrit \
321321
-it superlists*
322322
----
@@ -400,11 +400,11 @@ or on a server, so we'll use the `-e` flag again:
400400
[subs="specialcharacters,quotes"]
401401
----
402402
$ *docker build -t superlists . && docker run \
403-
-p 8888:8888 \
404-
-v ./src/db.sqlite3:/src/db.sqlite3 \
405-
-e DJANGO_SECRET_KEY=sekrit \
406-
-e DJANGO_ALLOWED_HOST=localhost \
407-
-it superlists*
403+
-p 8888:8888 \
404+
--mount type=bind,source=./src/db.sqlite3,target=/src/db.sqlite3 \
405+
-e DJANGO_SECRET_KEY=sekrit \
406+
-e DJANGO_ALLOWED_HOST=localhost \
407+
-it superlists*
408408
----
409409

410410

0 commit comments

Comments
 (0)