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.2.tar.gz (58.9 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.2-py3-none-any.whl (63.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: docker_dsl-0.1.2.tar.gz
  • Upload date:
  • Size: 58.9 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.2.tar.gz
Algorithm Hash digest
SHA256 8cd50f0b0623c2673d2b6894447d58719fd1a72ac4ae357781e0d33a61305948
MD5 a21e445de7864c7eb674c433a4b5b1a8
BLAKE2b-256 0ef4758df01842737a2c8f9b788f95fc08d21f88ef6fb9a68b5cfd6cfe3a5aed

See more details on using hashes here.

Provenance

The following attestation bundles were made for docker_dsl-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: docker_dsl-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 63.0 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d91e20da2521788936f9ff454c43088cbc8eadf2417fbc5b6de3c2ebcb7f529a
MD5 2fcde42c35868da0341a7909719b1758
BLAKE2b-256 78b416cee124aadfc911ce8b2ca85608a12602b16c88dfd6ac877ac5740cb535

See more details on using hashes here.

Provenance

The following attestation bundles were made for docker_dsl-0.1.2-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

This release

0.1.2 This release

2 files

0.1.1

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