-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
dockerfile: implement hooks for RUN
instructions
#4669
Conversation
2058c6c
to
8d5b827
Compare
63780df
to
2151fc6
Compare
@tonistiigi @thaJeztah PTAL 🙏 |
4f97a38
to
d9c157a
Compare
@tonistiigi Can we merge this, so that we can do more experiments on repro builds etc. ? |
Rebased |
@AkihiroSuda One thing I don't like about this approach is that it separates the hook logic away from the Dockerfile; and thus the logic for building the container is split. Most likely the container won't build correctly w/o the hooks (e.g. because it will use the non-snapshot package repository); but there's no indication in the Dockerfile itself. At least this would be clearer (Can nicely throw an error if hook is missing).:
I'd prefer it even more if it's all in the same Dockerfile:
Clear and self-contained. Easy to pass to e.g. Kaniko for example etc. Although that would expand the Docker vocabulary so that sounds like a much bigger PR. |
@janjongboom The fact that it isn't in the Dockerfile is exactly what makes this feature so useful. Now we can for example mount the credentials for our mirror transparently, which has two benefits:
|
I'm in favor of it. |
@thompson-shaun @tonistiigi Which release will contain this PR? 🙏 |
Rebased. |
Rerebased |
Rererebased |
Rerererebased @tonistiigi @thaJeztah PTAL 🙏 |
@thompson-shaun @tonistiigi I moved this from the |
Will be used in the follow-up commits for implementing "Dockerfile hooks" (issue 4576) Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Close issue 4576 - - - e.g., ```bash buildctl build \ --frontend dockerfile.v0 \ --opt hook="$(cat hook.json)" ``` with `hook.json` as follows: ```json { "RUN": { "entrypoint": ["/dev/.dfhook/entrypoint"], "mounts": [ {"from": "example.com/hook", "target": "/dev/.dfhook"}, {"type": "secret", "source": "something", "target": "/etc/something"} ] } } ``` This will let the frontend treat `RUN foo` as: ```dockerfile RUN \ --mount=from=example.com/hook,target=/dev/.dfhook \ --mount=type=secret,source=something,target=/etc/something \ /dev/.dfhook/entrypoint foo ``` `docker history` will still show this as `RUN foo`. Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Originally posted by @AkihiroSuda in #4576 (comment) |
Close #4576
e.g.,
buildctl build \ --frontend dockerfile.v0 \ --opt hook="$(cat hook.json)"
with
hook.json
as follows:This will let the frontend treat
RUN foo
as:RUN \ --mount=from=example.com/hook,target=/dev/.dfhook \ --mount=type=secret,source=something,target=/etc/something \ /dev/.dfhook/entrypoint foo
docker history
will still show this asRUN foo
.Buildx integration
To specify
--opt
via buildx, see:buildx build --opt
(EXPERIMENTAL) docker/buildx#2260Eventually buildx should have a proper
--hook=<FILE>
option.Probably, it should also read
~/.docker/buildx/hooks/*.json
by default.Use cases
Reproducible builds
A hook can be used for wrapping
apt-get
command to usesnapshot.debian.org
for reproducing package versions without modifying the Dockerfile.The
/dev/.dfhook/entrypoint
script can be like this:A hook may also push/pull dpkg blobs to an OCI registry (or whatever) for efficient caching.
Cross-compilation
xx-apt
, etc. (https://github.com/tonistiigi/xx) can be reimplemented as a hook.Malware detection
A hook may use seccomp, etc. to hook the syscalls and detect malicious actions, etc.
Enterprise networking
Enterprise networks often require installing a MITM proxy cert.
This can be easily automated with a hook.
FAQs