From ea6c141cb6faaf9d6d25d646fee2d30101fc6fce Mon Sep 17 00:00:00 2001 From: Yann Bizeul Date: Sun, 11 Feb 2024 19:00:31 +0100 Subject: [PATCH 1/2] /var/lib/docker pre-populate doc Adds documentation to pre populate /var/lib/docker with docker-in-docker --- .../customize-the-image.md | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/content/docs/latest/installing/customizing-the-image/customize-the-image.md b/content/docs/latest/installing/customizing-the-image/customize-the-image.md index d1688ddf..6138b24d 100644 --- a/content/docs/latest/installing/customizing-the-image/customize-the-image.md +++ b/content/docs/latest/installing/customizing-the-image/customize-the-image.md @@ -82,6 +82,48 @@ When you place systemd services under `/etc/systemd/system/my.service` and they You can even pre-populate the container image story by copying the folders `/var/lib/docker` and `/var/lib/containerd` over from a booted Flatcar instance. +### Customize /var/lib/docker + +You can pre-populate `/var/lib/docker` to provide a ready-to-use docker environment with images and containers. + +One solution is to setup the docker environment on another flatcar instance and archive `/var/lib/docker` with `tar` for example, then use the method above to un-`tar` into root partition (9). This requires setting up a flatcar instance and communicate with the OS to copy the content of `/var/lib/docker` to your build machine. + +A more convenient way is to use [docker-in-docker](https://hub.docker.com/_/docker) on any docker environment on which you have privileged access. + +You start by running docker-in-docker container: + +```shell +# Run docker-in-docker in the backgroud. +# We mount local directory as a location to send /var/lib/docker archive +# Do NOT try to bind a directory to /var/lib/docker directly as this might +# produce incompatible images (vfs instead of overlay2) depending on your +# environment. +docker run --name dind --privileged --rm -d -v $(pwd):/build docker:dind +``` + +Then you can interact with docker-in-docker environment and prepare images: + +```shell +docker exec -it dind sh +docker pull nginx +``` + +Create the `tar` archive that contains your docker environment: + +```bash +# We mounted the /build directory to copy the archive +tar -cf /build/docker-images.tar /var/lib/docker +``` + +During the build of your flatcar image, you can mount the root partition (9) and extract the `tar` archive: + +```bash +# We mounted root partition (9) on /mnt +tar -xf /build/docker-images.tar -C /mnt +``` + +You can now unmount `/mnt` and finish preparing your final image. + ## Customization through booting with Packer, VMware base VMs, or chroot/systemd-nspawn This section serves as a big warning. If you use a booted image, even if it was only booted by being a chroot or a systemd-nspawn container, you will get a lot of problems. From aa32ab21b4d2284b6684bf254ce75ec331954a65 Mon Sep 17 00:00:00 2001 From: Yann Bizeul Date: Mon, 12 Feb 2024 14:15:39 +0100 Subject: [PATCH 2/2] Minor changes --- .../customizing-the-image/customize-the-image.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/content/docs/latest/installing/customizing-the-image/customize-the-image.md b/content/docs/latest/installing/customizing-the-image/customize-the-image.md index 6138b24d..a5ecb534 100644 --- a/content/docs/latest/installing/customizing-the-image/customize-the-image.md +++ b/content/docs/latest/installing/customizing-the-image/customize-the-image.md @@ -86,11 +86,11 @@ You can even pre-populate the container image story by copying the folders `/var You can pre-populate `/var/lib/docker` to provide a ready-to-use docker environment with images and containers. -One solution is to setup the docker environment on another flatcar instance and archive `/var/lib/docker` with `tar` for example, then use the method above to un-`tar` into root partition (9). This requires setting up a flatcar instance and communicate with the OS to copy the content of `/var/lib/docker` to your build machine. +One solution is to setup the Docker environment on another Flatcar instance and archive `/var/lib/docker` with `tar` for example, then use the method above to un-`tar` into root partition (9). This requires setting up a Flatcar instance and communicate with the OS to copy the content of `/var/lib/docker` to your build machine. -A more convenient way is to use [docker-in-docker](https://hub.docker.com/_/docker) on any docker environment on which you have privileged access. +A more convenient way is to use [Docker-in-Docker](https://hub.docker.com/_/docker) on any Docker environment on which you have privileged access. -You start by running docker-in-docker container: +You start by running a Docker-in-Docker container: ```shell # Run docker-in-docker in the backgroud. @@ -101,21 +101,21 @@ You start by running docker-in-docker container: docker run --name dind --privileged --rm -d -v $(pwd):/build docker:dind ``` -Then you can interact with docker-in-docker environment and prepare images: +Then you can interact with the docker-in-docker environment and prepare images: ```shell docker exec -it dind sh docker pull nginx ``` -Create the `tar` archive that contains your docker environment: +Create the `tar` archive that contains your Docker environment: ```bash # We mounted the /build directory to copy the archive tar -cf /build/docker-images.tar /var/lib/docker ``` -During the build of your flatcar image, you can mount the root partition (9) and extract the `tar` archive: +During the build of your Flatcar image, you can mount the root partition (9) and extract the `tar` archive: ```bash # We mounted root partition (9) on /mnt