Skip to main content

docker-dsl

docker-dsl banner

PyPI Python Docs License: MIT

An imperative, context-manager-based Python DSL for authoring multi-stage Dockerfiles. Write builds with with blocks, conditionals, comprehensions, and reusable helpers, then render one recipe into many Dockerfile variants.

Install

Run it through uvx, no install needed:

uvx docker-dsl --help

Quickstart

Write a recipe module, minimal.py:

from docker_dsl import Stage
from docker_dsl import context as ctx

ctx.register("tag", str)

with Stage("ubuntu:24.04") as s:
    s.arg("APP_TAG", ctx.tag or "latest", env=True)
    s.workdir("/app")
    with s.run() as r:
        r.echo("hello from docker-dsl") > "/app/greeting.txt"
    s.cmd("cat", "/app/greeting.txt")

Render it:

uvx docker-dsl minimal --tag=v1.0.0 --out Dockerfile

Dockerfile now holds:

# syntax=docker/dockerfile:1
FROM ubuntu:24.04 AS base
ARG APP_TAG=v1.0.0
ENV APP_TAG=${APP_TAG}
WORKDIR /app
RUN echo "hello from docker-dsl" > /app/greeting.txt
CMD ["cat", "/app/greeting.txt"]

Change --tag and render again for a different Dockerfile from the same recipe.

Why

  • RUN chains glued with && are fragile. The run builder accumulates commands in Python and emits one correct RUN, with cd scoping restored for you.
  • Variants drift apart. One recipe takes --gpu=true|false and renders both a GPU and a CPU image from the same code path, instead of two Dockerfiles that diverge over time.
  • BuildKit mounts are easy to get wrong. cache, secret, and bind are scoped context managers, so every RUN inside the block picks them up and nothing leaks out.

Docs

The documentation has a tutorial, task-focused guides (multi-stage builds, mounts, smart apt, the run builder, reusable helpers, and the CLI), and the full API reference.

License

This project is licensed under the MIT License; see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docker_dsl-0.1.1.tar.gz (58.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docker_dsl-0.1.1-py3-none-any.whl (62.9 kB view details)

Uploaded Python 3

File details

Details for the file docker_dsl-0.1.1.tar.gz.

File metadata

  • Download URL: docker_dsl-0.1.1.tar.gz
  • Upload date:
  • Size: 58.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for docker_dsl-0.1.1.tar.gz
Algorithm Hash digest
SHA256 32cd52585f63d547df250f21b14588ee56cbb5be7ad6db7d2c0b43c08261c3fa
MD5 981623e79fafebd833076fef0b3d1e13
BLAKE2b-256 f358905b68e58d13669e102bd27885c9cc815402a85ca77dd60282ca8033c2f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for docker_dsl-0.1.1.tar.gz:

Publisher: release-pypi.yml on yasyf/docker-dsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file docker_dsl-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: docker_dsl-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 62.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for docker_dsl-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4750aa5479aadc219a45487dc6881dc6819231492ca83f729694760d245f8c89
MD5 56980f258d51e065df53133b7d4b9089
BLAKE2b-256 258cee471f5fd25d3d63b97c9280e8424de8a1a34f7adb956743c3d158393293

See more details on using hashes here.

Provenance

The following attestation bundles were made for docker_dsl-0.1.1-py3-none-any.whl:

Publisher: release-pypi.yml on yasyf/docker-dsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.2

2 files

This release

0.1.1 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page