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

Is there a way to refer to a container rather than an image in multistage builds? #5914

Open
ytimenkov opened this issue Jan 17, 2025 · 0 comments

Comments

@ytimenkov
Copy link

Hi!

I've been using buildah's multi-container feature to create slim runtime images for a while now (something inspired by https://projectatomic.io/blog/2017/08/buildah-getting-fit/) - a technique to have a separate container or host with package manager and have a target runtime container where packages are installed. (OpenSUSE project even provides images for such purpose - they contain RPM database, but no rpm).

However this process requires a bit of scripting to start containers and juggle with mounts and is not that expressive.

Recently I discovered that Dockerfile syntax now allows to add a different set of mounts to RUN instruction, so I tried to check if it's possible to achieve same effect with just Containerfiles:

FROM registry.opensuse.org/opensuse/bci/bci-micro:latest AS base

RUN echo "Building..."
# ^^^^^^^^ This commits container to an image. The image will be (re)used in the final stage

FROM registry.opensuse.org/opensuse/tumbleweed AS zypp

RUN zypper modifyrepo --keep-packages --all

RUN \
    --mount=type=cache,destination=/var/cache/zypp \
    --mount=type=bind,from=base,destination=/target,rw \
    zypper --non-interactive --gpg-auto-import-keys --installroot=/target install ripgrep
# ^^^ This modifies running container, but not the image. Image is committed after finishing "base" stage

FROM base

RUN --mount=type=bind,from=zypp,destination=/root echo "Done building"
# ^^^^ This is just to add dependency on zypp stage, otherwise it is ignored.

Unfortunately it doesn't work, because while RUN instructions take stage as a container, FROM instructions take stage as an image. The difference is that container is committed to image right before switching to the next stage (FROM tumbleweed AS zypp) and therefore any changes done to base container are not propagated (just discarded).

So that's my question - is there any way to create Containerfile which allows such use-case?

P.S. thanks for a great tool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant