11---
2- icon : lucide/terminal
2+ icon : lucide/package
33title : Building containers
4- description : Install and run Pixi environments inside Dagger containers.
4+ description : Install Pixi environments in Dagger containers and build runtime images without shipping Pixi itself .
55---
66
7- # Building Containers
7+ # Building containers
88
9- ` install ` copies the source tree into a Pixi image, mounts Pixi caches, and runs
10- ` pixi install --locked ` for a named environment inside a
11- [ Dagger] ( https://dagger.io ) container. The returned container is a builder-style
12- container and includes the Pixi binary.
9+ This is the module's core feature: turning a [ Pixi] ( https://pixi.prefix.dev/latest/ )
10+ workspace into a [ Dagger] ( https://dagger.io ) container with one or more named
11+ environments installed.
1312
14- ``` python
15- from dagger import dag
13+ Pixi remains responsible for solving, locking, and installing. The module provides
14+ the Dagger shape around it: source mounting, cache volumes, environment selection,
15+ Dagger SDK codegen overlays, and runtime images that keep the installed
16+ ` .pixi/envs/* ` directories but leave the Pixi binary behind.
1617
17- ctr = await dag.pixi(source = src).install(environment = " default" )
18- ```
18+ ??? abstract "The mental model"
1919
20- Install more than one environment into the same container:
20+ ```mermaid
21+ graph LR
22+ P["Pixi<br/><i>source tree</i>"] -->|workspace / get_workspaces| WS["PixiWorkspaceSource<br/><i>one per pixi.lock</i>"]
23+ P -->|install / run / runtime| Root["Default workspace<br/><i>path = .</i>"]
24+ WS -->|install_environments| Builder["Builder container<br/><i>Pixi image</i>"]
25+ Builder -->|runtime_environments| Runtime["Runtime container<br/><i>no Pixi binary</i>"]
26+ ```
2127
22- ``` python
23- ctr = await dag.pixi(source = src).install_environments(environments = [" default" , " docs" ])
24- ```
28+ - **`Pixi`** holds your source tree. Its root functions use the workspace at `.`
29+ and accept `path` when your Pixi workspace lives deeper in the tree.
30+ - **`PixiWorkspaceSource`** is one Pixi workspace rooted at a `pixi.lock`. It is
31+ useful when you want to keep a workspace object around explicitly.
32+ - **Builder containers** use a Pixi image and can run `pixi install` / `pixi run`.
33+ - **Runtime containers** copy selected `.pixi/envs/*` directories and an
34+ entrypoint into a fresh image.
2535
26- Use ` run ` for one-off commands:
36+ ## ` install ` - the one-call path
2737
28- ``` python
29- ctr = await dag.pixi(source = src).run(args = [" python" , " --version" ])
30- ```
38+ ` install ` returns a builder-style container with one Pixi environment installed.
3139
32- Use ` runtime ` for a deployable image without Pixi. It installs with Pixi in a
33- builder, copies the selected ` .pixi/envs/* ` directories and a Bash entrypoint
34- into a runtime image, and leaves the Pixi binary behind.
40+ === "CLI"
3541
36- ``` python
37- runtime = await dag. pixi( source = src).runtime( environment = " default" )
38- ```
42+ ```console
43+ $ dagger call pixi install -- environment default
44+ ```
3945
40- For a final image with several Pixi environments:
46+ === "Python SDK"
4147
42- ``` python
43- runtime = await dag.pixi(source = src).runtime_environments(
44- environments = [" default" , " model-downloader" ],
45- entrypoint_environment = " default" ,
46- )
47- ```
48+ ```python
49+ from dagger import dag
50+
51+ ctr = await dag.pixi(source=src).install(environment="default")
52+ ```
53+
54+ Use ` run ` for a one-off command in that environment:
55+
56+ === "CLI"
57+
58+ ```console
59+ $ dagger call pixi run --args python --args --version
60+ ```
61+
62+ === "Python SDK"
63+
64+ ```python
65+ ctr = await dag.pixi(source=src).run(args=["python", "--version"])
66+ ```
67+
68+ ## Multiple environments
69+
70+ ` install_environments ` installs several Pixi environments into the same builder
71+ container.
72+
73+ === "CLI"
74+
75+ ```console
76+ $ dagger call pixi install-environments \
77+ --environments default \
78+ --environments docs
79+ ```
80+
81+ === "Python SDK"
82+
83+ ```python
84+ ctr = await dag.pixi(source=src).install_environments(
85+ environments=["default", "docs"],
86+ )
87+ ```
88+
89+ To install every declared environment, use ` install_all_environments ` .
90+
91+ ## Runtime images
92+
93+ Use ` runtime ` or ` runtime_environments ` for deployable images. The module installs
94+ with Pixi in a builder, copies the selected ` .pixi/envs/* ` directories and a Bash
95+ entrypoint into a runtime image, and leaves the Pixi binary behind.
96+
97+ === "CLI"
98+
99+ ```console
100+ $ dagger call pixi runtime-environments \
101+ --environments default \
102+ --environments model-downloader \
103+ --entrypoint-environment default
104+ ```
105+
106+ === "Python SDK"
107+
108+ ```python
109+ runtime = await dag.pixi(source=src).runtime_environments(
110+ environments=["default", "model-downloader"],
111+ entrypoint_environment="default",
112+ )
113+ ```
48114
49115For a tighter runtime image, copy only the source paths that target needs:
50116
@@ -63,22 +129,22 @@ runtime = await dag.pixi(source=src).runtime_environments(
63129)
64130```
65131
66- Use ` path ` when the Pixi workspace is not at the source root:
132+ ` runtime_source_paths ` is source-root-relative and accepts paths or glob patterns.
133+ For a nested Pixi workspace, include the workspace prefix when needed.
67134
68- ``` python
69- ctr = await dag.pixi(source = src).install_environments(
70- path = " services/api" ,
71- environments = [" default" , " docs" ],
72- )
73- ```
135+ ## Choosing images
74136
75- Pixi features become concrete through environments. For example, an environment
76- declared with ` features = ["docs"] ` is installed by passing the environment name,
77- not the feature name .
137+ The default builder image is ` ghcr.io/prefix-dev/pixi:0.70.2 ` , or the concrete
138+ version resolved from ` requires-pixi ` when the workspace declares one. Pass
139+ ` pixi_version ` or ` image ` to override it .
78140
79141The default runtime image is ` ubuntu:noble ` . Pass ` runtime_image ` or
80- ` runtime_base_container ` to add operating-system packages before the Pixi
81- environments are copied in.
142+ ` runtime_base_container ` when the final image needs operating-system packages,
143+ users, certificates, or another base.
144+
145+ ## Dagger modules as dependencies
82146
83- The default image is ` ghcr.io/prefix-dev/pixi:0.70.2 ` . Pass ` image ` or
84- ` pixi_version ` to override the builder image.
147+ If the workspace is itself a Dagger module, the module runs Dagger codegen and
148+ overlays the generated SDK before installing, so the generated ` dagger-io ` package
149+ is present even when ` sdk/ ` is gitignored in CI. This is on by default and is a
150+ no-op for non-Dagger projects.
0 commit comments