{"id":1463,"library":"dockerfile-parse","title":"Dockerfile Parse","description":"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.","status":"active","version":"2.0.1","language":"en","source_language":"en","source_url":"https://github.com/containerbuildsystem/dockerfile-parse","tags":["docker","dockerfile","parser","build","container","analysis"],"install":[{"cmd":"pip install dockerfile-parse","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"symbol":"DockerfileParser","correct":"from dockerfile_parse import DockerfileParser"}],"quickstart":{"code":"from pprint import pprint\nfrom dockerfile_parse import DockerfileParser\n\ndfp = DockerfileParser()\ndfp.content = \"\"\"\nFROM base\nLABEL foo=\"bar baz\"\nUSER me\n\"\"\"\n\n# Print the parsed structure:\nprint(\"--- Structure ---\")\npprint(dfp.structure)\n\n# Print labels:\nprint(\"\\n--- Labels ---\")\npprint(dfp.labels)\n\n# Set a new base image:\ndfp.baseimage = 'centos:7'\n\n# Print the new Dockerfile content with an updated FROM line:\nprint(\"\\n--- Updated Dockerfile Content ---\")\nprint(dfp.content)","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to Python 3.6 or newer. The `requires_python` specifies `>=3.6`.","message":"Python 2 support was completely dropped in version 2.0.0. Applications running on Python 2.x will fail to import or run `dockerfile-parse` version 2.0.0 or newer.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure your Python 2 environment is at least Python 2.7 if you must use an older version of the library (pre-2.0.0).","message":"Support for Python 2.6 was dropped in version 0.0.14.","severity":"breaking","affected_versions":">=0.0.14"},{"fix":"Upgrade to `dockerfile-parse` version 1.1.0 or newer to correctly parse Dockerfiles that utilize the `escape` directive.","message":"Older versions of `dockerfile-parse` (prior to 1.1.0) do not properly support the `escape` directive in Dockerfiles.","severity":"gotcha","affected_versions":"<1.1.0"},{"fix":"Update to version 0.0.14 or newer to ensure correct processing of multi-line instructions when programmatically adding lines to a Dockerfile.","message":"Handling of multi-line instructions, specifically with the `add_lines_at()` method, had issues in versions prior to 0.0.14.","severity":"gotcha","affected_versions":"<0.0.14"},{"fix":"Upgrade to version 0.0.15 or later for more robust error handling and clearer diagnostics when dealing with potentially incorrect LABEL syntax.","message":"Error reporting for incorrect LABEL syntax was improved in version 0.0.15. Older versions might provide less descriptive errors or unexpected behavior for malformed LABEL instructions.","severity":"gotcha","affected_versions":"<0.0.15"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}