Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds documentation to pre populate /var/lib/docker with docker-in-docker #303

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
ybizeul marked this conversation as resolved.
Show resolved Hide resolved

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.
ybizeul marked this conversation as resolved.
Show resolved Hide resolved

You start by running docker-in-docker container:
ybizeul marked this conversation as resolved.
Show resolved Hide resolved

```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:
ybizeul marked this conversation as resolved.
Show resolved Hide resolved

```shell
docker exec -it dind sh
docker pull nginx
```

Create the `tar` archive that contains your docker environment:
ybizeul marked this conversation as resolved.
Show resolved Hide resolved

```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:
ybizeul marked this conversation as resolved.
Show resolved Hide resolved

```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.
Expand Down