Skip to main content

docked

A human-friendly alternative to Dockerfile. It's a Python library for generating Docker images, with API designed to be safe, secure, and easy-to-use correctly.

Features:

  • Just a Python library. No custom syntax, no monkey-patching, no magic. Get the full power of Python.
  • 100% type-safe. The code base is fully type annotated and type checked, and we put a lot of effort to make the best API that makes invalid or insecure usage impossible.
  • Supports all versions of Dockerfile and Containerfile standards and syntax.
  • Automatically picks the most compatible syntax version based on the features you use.
  • Built-in linter to help you to make safe and effective containers.
  • API is very close to that of Dockerfile.
  • Our top priority is to provide a friendly and simple way of making Docker images. We carefully designed our API to avoid the most common mistakes of Docker newcomers.
  • Generates a human-readable and valid Dockerfile, so you can use it together with any other tools without any vendor-lock.

Why

The Dockerfile already exists, and yet we made this project. THere are many good reasons for that:

  • Python is powerful. You get loops, conditions, environment variables, command-line tools, and a lot of other cool stuff that Dockerfile will never get.
  • Python has a great tooling. You get linters, type-checker, autoformatters, debugger, autoomplete, syntax highlighting, and so on to make your code easy to write, read, and maintain.
  • Python has a great ecosystem. You can use docker.py to go beyond of just building containers, boto3 to access S3 secrets at build-time, slack SDK to send notifications about build status, toml to read config files, dotenv to support .env files, and anything else you can ever imagine.
  • Python has a consistent and expressive syntax designed by smart people over many years.

Our goal was to provide the best possible IDE assistance to the users. All API is concise, precise, explicit, well-documented, and 100% type anntated. Docked will give your team greater learning experience than Docker can ever dream of.

Installation

python3 -m pip install docked

Usage

No more words, it's time for code!

import docked as d

stage = d.Stage(
    base=d.BaseImage('python', tag='3.11-alpine'),
    build=[
        d.RUN(
            d.cmd.pip_install('cowsay'),
        ),
    ],
    run=[
        d.CMD(['cowsay', 'hello world!'])
    ],
)
image = d.Image(stage)

if __name__ == '__main__':
    image.lint()
    print(image)

What's happening:

  1. d.Image is equivalent of a single Dockerfile file. It wraps one or more stages. YOu can have many stage in per image in multi-stage builds.
  2. d.Stage is a single "stage". You can have multiple s
  3. base=d.BaseImage(...) is the image on which the stage is based. It can be anything available on Docker Hub.
  4. build=[...] is a list of steps to perform when building the image. Most of the steps correspond to a Docker instruction with the same name.
  5. d.RUN(...) is the same as RUN in Docker. It tells to run a list of the given shell-commands when building the image.
  6. d.cmd.pip_install is a convenience function that will produce a command for pip to install the given packages. It's better than just passing pip install cowsay because it will produce a command that follows the best practice of installing Python packages in Docker images. Docked provides a few most useful convenience functions but not many, we don't want it to be too verbose.
  7. run=[...] is a list of Docker instruction describing not how the image should be build but how it will behave when it is run. A good example is VOLUME which cannot mount volumes when building an image, and so it can be passed in run=[...] but not in build=[...]
  8. image.lint() runs built-in linter that will make sure we follow the best practice of building Docker images.
  9. print(image) generates a Dockerfile and prints it into stdout.

Now, pipe it into docker and run the image:

python3 examples/cowsay.py | docker buildx build --tag=hello:latest -
docker run hello:latest

And you should see Mr. Cow:

  ____________
| hello world! |
  ============
            \
             \
               ^__^
               (oo)\_______
               (__)\       )\/\
                   ||----w |
                   ||     ||

Learn more

  1. docked.orsinium.dev hosts documentation.
  2. examples directory has, you guessed it, examples. All are real and runnable.
  3. You should be able to just install docked and start using it. It has quite good type annotations and docstrings, so let your IDE guide you.

Metadata

Release files for docked 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docked 0.1.0
File Size Uploaded Provenance Actions
docked-0.1.0.tar.gz 25.2 kB Without provenance Details for docked-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for docked 0.1.0
File Interpreter ABI Platform Actions
docked-0.1.0-py3-none-any.whl Python 3 none any Details for docked-0.1.0-py3-none-any.whl

Total release size: 44.8 kB

Release files / docked-0.1.0.tar.gz

Download URL docked-0.1.0.tar.gz
Size 25.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ae88318d7c3bf4da094897560ce8c423a6cbf6dedc0294243e125e6be81b71d7
BLAKE2b-256 checksum
How to use checksums
aa48a7b7ab1bda51ad8a1c503babec41314743b47be9cfcde997d4cc967c7ab0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Release files / docked-0.1.0-py3-none-any.whl

Download URL docked-0.1.0-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1dc3ea96bac469627c8f2030e37aecb8429d8e9f4e0770291eaac5728c27c724
BLAKE2b-256 checksum
How to use checksums
96a4a6b1912fd95484f81fc464a8a7611b30c85c88c6303746281e06b2b56373
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Security for docked 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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