|
| 1 | +# Proposal: Build to Docker Daemon |
| 2 | + |
| 3 | +## Motivation |
| 4 | + |
| 5 | +Currently, Jib builds and pushes container images to a Docker registry without the need for a Docker daemon. However, for development use cases where the developer does not have a registry set up but do have a Docker daemon available, they may wish to build to the Docker daemon directly. |
| 6 | + |
| 7 | +## Goals |
| 8 | + |
| 9 | +* Build to local Docker daemon |
| 10 | +* Build to [minikube](https://github.com/kubernetes/minikube) (remote) Docker daemon |
| 11 | +* Minimize extra configuration |
| 12 | + |
| 13 | +## Constraints |
| 14 | + |
| 15 | +* Building to local Docker daemon should be an extra feature, not the default |
| 16 | + |
| 17 | +## Intended Workflow |
| 18 | + |
| 19 | +Building to a Docker daemon should be as simple as calling a new task/goal (`jib:buildDocker` for Maven and `jibBuildDocker` for Gradle). |
| 20 | + |
| 21 | +## Implementation |
| 22 | + |
| 23 | +There are three main parts to implementing this proposal: |
| 24 | + |
| 25 | +1. Build an image tarball stream, with the format (see [tarexport/load.go](https://github.com/moby/moby/blob/master/image/tarexport/load.go) for full details): |
| 26 | + - Each layer as a GZipped tarball named with its SHA256 digest. |
| 27 | + - A `config.json` as the container config, containing: |
| 28 | + - `OS`: `linux` |
| 29 | + - `RootFS.DiffIDS`: in-order [diff IDs](https://github.com/opencontainers/image-spec/blob/master/config.md#layer-diffid) for all the uncompressed layers |
| 30 | + - A `manifest.json` containing the following fields: |
| 31 | + - `Config`: The filename of the container config JSON |
| 32 | + - `Layers`: in-order list of filenames for each layer |
| 33 | +2. Send the image tarball stream to the Docker daemon using [`docker load`](https://docs.docker.com/engine/reference/commandline/load/) CLI command. |
| 34 | + |
| 35 | +Note that currently, build, cache, and push are all in `BuildImageSteps`. In order to implement parts 2 and 3, these stages would need be modularized so that push can be replaced with build image tarball stream and send to Docker daemon. |
| 36 | + |
| 37 | +If in the future, we would like to not use the `docker` CLI, we would need to: |
| 38 | + |
| 39 | +1. Find the Docker daemon. |
| 40 | + - This should use the same Docker daemon that the `docker` CLI would. |
| 41 | + - The default host is `unix:///var/run/docker.sock` or `tcp://127.0.0.1:2375`. |
| 42 | + - Remote Docker daemon can be configured with environment variables, such as those output by `minikube docker-env`. These include: |
| 43 | + - `DOCKER_TLS_VERIFY` |
| 44 | + - `DOCKER_HOST` |
| 45 | + - `DOCKER_CERT_PATH` |
| 46 | + - `DOCKER_API_VERSION` |
| 47 | +2. Send the image tarball stream to the Docker daemon using the [Docker Engine API](https://docs.docker.com/engine/api/v1.37/#operation/ImageLoad). This can be done manually with HTTP requests, or by using a Docker-Java client like [docker-java](https://github.com/docker-java/docker-java). |
0 commit comments