First image¶
Build a container image from a Dockerfile on Nebius, then run a job on it. There is no Docker on your machine and no registry setup.
View example files ↗: image_quickstart.py · Related reference: Images →
"""The image quickstart: build a Dockerfile, reuse it, run a job on it.
The first run builds the image on a CPU job (a few minutes) and pushes it
to the project's ``generated-images`` registry. Later runs, and the second
``build()`` below, find the same tag and reuse it. Uses the active Nebius
profile.
"""
import nebius_serverless as ns
DOCKERFILE = """\
FROM python:3.12-slim-bookworm
RUN pip install --no-cache-dir requests==2.32.3
"""
def main() -> None:
"""Build (or reuse) the image, then run one CPU job on it."""
image = ns.Image(dockerfile_string=DOCKERFILE)
# Builds the first time; returns the reference either way.
ref = image.build()
# Same Dockerfile, same tag: nothing is built.
assert image.build() == ref
job = ns.Job(
command=[
"python",
"-c",
"import requests; print(requests.__version__)",
],
image=ref,
timeout="15m",
).create()
job.wait()
job.display()
if __name__ == "__main__":
main()
What happens¶
ns.Image(dockerfile_string=...)holds the Dockerfile. Pass a path instead withns.Image("./Dockerfile"). Nothing contacts Nebius yet.build()looks for the project'sgenerated-imagesContainer Registry and creates it on the first build.- The tag is
sha-plus a hash of the Dockerfile. If the registry already has that tag,build()printsReusing ...and returns at once. A Dockerfile is built once, and an edited one gets a new tag. - Otherwise
build()runs kaniko on a CPU job, waits for it, and printsPushed .... A first build takes about two minutes. build()returns the image reference,cr.<region>.nebius.cloud/<registry>/<name>:<tag>. Jobs in the same project pull it without credentials.
A build that does not end COMPLETED raises ns.BuildFailed; its resource_id is the build job, and nebius ai job logs <id> shows why. build(dry_run=True) returns the reference, whether it would be reused, and the build job request, and creates nothing.
Credentials¶
The push uses your own credentials, the same ones that create jobs. Each build stores a short-lived access token as a new version of the generated-images-push MysteryBox secret, passes it to the build job, and deletes that version when the build ends. RUN steps share the build container, so build only Dockerfiles you trust.
Limits¶
- The build context is the Dockerfile alone.
COPYof local files is not supported yet;COPY --from=<image>works. - The Dockerfile must be at most 64 KiB.
Next¶
Use the image for a task, see every option in the Images reference, or step through a GPU build in the image notebook.