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

Support the full Dockerfile syntax in modal.Image APIs #2922

Open
danielgafni opened this issue Mar 4, 2025 · 2 comments
Open

Support the full Dockerfile syntax in modal.Image APIs #2922

danielgafni opened this issue Mar 4, 2025 · 2 comments

Comments

@danielgafni
Copy link

danielgafni commented Mar 4, 2025

I would like to reuse my existing Dockerfiles with Modal since I don't want to maintain multiple image definitions per app. Currently, this is problematic, because Image.from_dockerfile doesn't support at least some of the build instructions like --build-arg and --target (for multi-stage builds). I also can't find a way to specify the build context (the context_mount argument is deprecated). The documentation mentions it's "automatically inferred" --- it would be great if the docs could elaborate on how exactly is this done under the hood.

Because of that, images have to be built outside of Modal, pushed to the container registry, and then imported to Modal, which complicates local development.

The automatic package discovery is nice but it's not very transparent how exactly does it work. My guess is that Modal checks for the presence of editable dependencies in the Python environment and infers their location? Is it also looking at the current (where the app is located) package dependencies? What if there are multiple pyproject.toml files (e.g. managed a monorepo managed by uv workspaces)? It doesn't seem to work correctly with local editable dependencies.


P.S. A very solid API for defining container builds in Python can be found in Dagger


Edit: found some mentions of the Python packages auto-discovery here, looks like auto-discovery is being deprecated anyway.

@thundergolfer
Copy link
Contributor

thundergolfer commented Mar 6, 2025

First of all thanks for the details issue report, much appreciated. It think as this issue encompasses more than just modal-client concerns https://modal.com/slack would be a good place to have this discussion 🙂.

it would be great if the docs could elaborate on how exactly is this done under the hood.

I agree! I'll get this actioned as I don't think it's obvious how we do this and thus can't understand if it was edge-cases where the auto-mounting would be wrong.

As to the --build-arg, you're right we don't support that. I can look at getting it supported.

As to --target, I haven't used this but it looks like a way to build a single stage in a multi-stage build. How would you want to use this within Modal, for debugging?

@danielgafni
Copy link
Author

danielgafni commented Mar 6, 2025

--target

I have a multi-stage Dockerfile shared for a few flavors of the image. I would like to specify the stage needed for Modal applications (it would improve layers caching).

slack

Will move there! I'm from the anam-org org.

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

2 participants