Dockerfile Parse is a Python library designed for programmatic manipulation and parsing of Dockerfile files. It provides structured access to Dockerfile instructions, making it suitable for tasks like static analysis, linting, and automated tooling around Docker container builds. The library is actively maintained, with version 2.0.1 being the current release, and it frequently receives updates for compatibility with newer Python versions.
Install & Compatibility
Where this runs
tested against v2.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.930 runs
installs and imports cleanly · install 0.0s · import 0.030s · 17.9MB
glibcpy 3.10–3.930 runs
installs and imports cleanly · install 1.5s · import 0.025s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
from dockerfile_parse import DockerfileParser
Initialize a `DockerfileParser` instance, load Dockerfile content as a string, and then access or modify its parsed elements such as the structure, labels, or the base image. The `content` attribute can be used to read or write the full Dockerfile string.
from pprint import pprint
from dockerfile_parse import DockerfileParser
dfp = DockerfileParser()
dfp.content = """
FROM base
LABEL foo="bar baz"
USER me
"""
# Print the parsed structure:
print("--- Structure ---")
pprint(dfp.structure)
# Print labels:
print("\n--- Labels ---")
pprint(dfp.labels)
# Set a new base image:
dfp.baseimage = 'centos:7'
# Print the new Dockerfile content with an updated FROM line:
print("\n--- Updated Dockerfile Content ---")
print(dfp.content)
dockerfile-parse --version
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.