@@ -299,25 +299,28 @@ It's possible to override this behavior by mounting host storage into
299
299
the system container's ` /var/lib/docker ` in order to persist the
300
300
inner Docker's image cache across system container life-cycles.
301
301
302
- To do this, follow these steps:
302
+ In fact, not only do inner Docker images persist; inner containers will also
303
+ persist (thought they will need to be restarted).
304
+
305
+ Here is an example:
303
306
304
307
1 ) Create a Docker volume on the host to serve as the persistent image cache for
305
308
the Docker daemon inside the system container.
306
309
307
310
``` console
308
- $ docker volume create my-image-cache
309
- my-image-cache
311
+ $ docker volume create myvol
312
+ myvol
310
313
311
314
$ docker volume list
312
315
DRIVER VOLUME NAME
313
- local my-image-cache
316
+ local myvol
314
317
```
315
318
316
319
2 ) Launch the system container and mount the volume into the system
317
320
container's ` /var/lib/docker ` directory.
318
321
319
322
``` console
320
- $ docker run --runtime=sysbox-runc -it --rm --hostname syscont --mount source=my-image-cache ,target=/var/lib/docker nestybox/alpine-docker
323
+ $ docker run --runtime=sysbox-runc -it --rm --hostname syscont --mount source=myvol ,target=/var/lib/docker nestybox/alpine-docker
321
324
/ #
322
325
```
323
326
@@ -342,45 +345,93 @@ REPOSITORY TAG IMAGE ID CREATED
342
345
busybox latest 19485c79a9bb 7 weeks ago 1.22MB
343
346
```
344
347
345
- 5 ) Exit the system container. Since it was started with the ` --rm `
346
- option, Docker will remove the system container from the system.
347
- However, the contents of the system container's ` /var/lib/docker `
348
- will persist since they are stored in volume ` my-image-cache ` .
348
+ 5 ) Create an inner container:
349
+
350
+ ``` console
351
+ / # docker run -d --name inner-container busybox tail -f /dev/null
352
+ 56ccb4bb33280f3f670956f6f06afde08e8219eb56c9d79a8b0e5d925ecee96d
353
+
354
+ / # docker ps
355
+ CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
356
+ 56ccb4bb3328 busybox "tail -f /dev/null" 4 seconds ago Up 2 seconds inner-container
357
+ ```
358
+
359
+ 6 ) Exit the system container.
360
+
361
+ This causes the inner container to be automatically stopped.
349
362
350
- 6 ) Start a new system container and mount the ` my-image-cache ` volume:
363
+ The contents of the system container's ` /var/lib/docker ` will persist since they
364
+ are stored in volume ` myvol ` .
365
+
366
+ 7 ) Start a new system container and mount ` myvol ` into it:
351
367
352
368
``` console
353
- $ docker run --runtime=sysbox-runc -it --rm --hostname syscont --mount source=my-image-cache,target=/var/lib/docker nestybox/alpine-docker
369
+ $ docker run --runtime=sysbox-runc -it --rm --hostname syscont --mount source=myvol,target=/var/lib/docker nestybox/alpine-docker
370
+ ```
354
371
372
+ 8 ) Start Docker inside:
373
+
374
+ ``` console
355
375
/ # dockerd > /var/log/dockerd.log 2>&1 &
376
+ ```
377
+
378
+ 9 ) Verify that the inner Docker images persisted:
356
379
380
+ ``` console
357
381
/ # docker image ls
358
382
REPOSITORY TAG IMAGE ID CREATED SIZE
359
383
busybox latest 19485c79a9bb 7 weeks ago 1.22MB
360
384
```
361
385
362
- As shown, the inner container images persist across the life-cycle of
363
- the system container.
386
+ There they are!
387
+
388
+ 10 ) Verify that the inner Docker container persisted:
389
+
390
+ ``` console
391
+ / # docker ps -a
392
+
393
+ CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
394
+ 56ccb4bb3328 busybox "tail -f /dev/null" 32 seconds ago Exited (255) 3 seconds ago inner-container
395
+
396
+ / # docker start inner-container
397
+ inner-container
398
+ / # docker ps -a
399
+ CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
400
+ 56ccb4bb3328 busybox "tail -f /dev/null" 42 seconds ago Up 1 second inner-container
401
+ ```
402
+
403
+ There is it is!
404
+
405
+ As shown, the inner container images and even inner containers persisted across
406
+ the life-cycle of the system container.
364
407
365
408
This is cool because it means that a system container can leverage an existing
366
409
Docker image cache stored somewhere on the host, thus avoiding having to pull
367
410
those inner Docker images from the network each time a new system container is
368
411
started.
369
412
370
- There are a couple of caveats to keep in mind:
413
+ There is a couple of important caveat to keep in mind:
414
+
415
+ - A Docker volume mounted into the system container's ` /var/lib/docker ` must
416
+ only be mounted on a ** single system container at any given time** . This is
417
+ a restriction imposed by the Docker daemon, which does not allow its image
418
+ cache to be shared concurrently among multiple daemon instances. Sysbox will
419
+ check for violations of this rule and report an appropriate error during
420
+ system container creation.
371
421
372
- - A persistent Docker image cache must only be mounted on a ** single
373
- system container at any given time** . This is a restriction imposed
374
- by the Docker daemon, which does not allow its image cache to be
375
- shared concurrently among multiple daemon instances. Sysbox will
376
- check for violations of this rule and report an appropriate error
377
- during system container creation.
422
+ - A Docker volume mounted into the system container's ` /var/lib/docker `
423
+ will ** inherit** any files present in that same directory as part of the system
424
+ container's image. Such files would be present when using system containers
425
+ that have preloaded inner container images.
378
426
379
- - A persistent Docker image cache mounted into the system container's
380
- ` /var/lib/docker ` directory will "mask" any files present in that same
381
- directory as part of the system container's image. Such files would be
382
- present when using system containers that have preloaded inner container
383
- images.
427
+ - In other words, if the system container comes preloaded with inner images,
428
+ those will be automatically transferred to the Docker volume when the
429
+ system container starts, and will persist across the system container
430
+ life-cycle.
431
+
432
+ - Note that this behavior is different than when bind-mounting host
433
+ directories into the system container ` /var/lib/docker ` (see next
434
+ section).
384
435
385
436
## Persistence of Inner Container Images using Bind Mounts
386
437
@@ -455,6 +506,19 @@ REPOSITORY TAG IMAGE ID CREATED
455
506
busybox latest 19485c79a9bb 7 weeks ago 1.22MB
456
507
```
457
508
458
- ```
509
+ There are a couple of caveats to keep in mind here:
459
510
460
- ```
511
+ - A host directory bind-mounted into the system container's ` /var/lib/docker ` must
512
+ only be mounted on a ** single system container at any given time** . This is
513
+ a restriction imposed by the Docker daemon, which does not allow its image
514
+ cache to be shared concurrently among multiple daemon instances. Sysbox will
515
+ check for violations of this rule and report an appropriate error during
516
+ system container creation.
517
+
518
+ - A host directory bind-mounted into the system container's ` /var/lib/docker `
519
+ will "mask" any files present in that same directory as part of the system
520
+ container's image. Such files would be present when using system containers
521
+ that have preloaded inner container images.
522
+
523
+ - This behavior differs from when Docker volume mounts are mounted into
524
+ the system container's ` /var/lib/docker ` (see prior section).
0 commit comments