https://github.com/containerbuildsystem/dockerfile-parse
Python library for parsing Dockerfile files.
https://github.com/containerbuildsystem/dockerfile-parse
dockerfile python
Last synced: 7 days ago
JSON representation
Python library for parsing Dockerfile files.
- Host: GitHub
- URL: https://github.com/containerbuildsystem/dockerfile-parse
- Owner: containerbuildsystem
- License: bsd-3-clause
- Created: 2015-06-18T15:59:46.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-08-12T04:45:15.000Z (over 1 year ago)
- Last Synced: 2025-09-27T19:01:48.669Z (4 months ago)
- Topics: dockerfile, python
- Language: Python
- Size: 237 KB
- Stars: 140
- Watchers: 11
- Forks: 53
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# dockerfile-parse
[![unittests status badge]][unittests status link]
[![coveralls status badge]][coveralls status link]
[![lgtm python badge]][lgtm python link]
[![lgtm alerts badge]][lgtm alerts link]
[![linters status badge]][linters status link]
Python library for parsing Dockerfile files.
## Installation
### From PyPI
```shell
pip install dockerfile-parse
```
### From git
Clone this git repo and install using the python installer
```shell
git clone https://github.com/containerbuildsystem/dockerfile-parse.git
cd dockerfile-parse
sudo pip install .
```
## Usage
```python
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:
pprint(dfp.structure)
pprint(dfp.json)
pprint(dfp.labels)
# Set a new base:
dfp.baseimage = 'centos:7'
# Print the new Dockerfile with an updated FROM line:
print(dfp.content)
```
[coveralls status badge]: https://coveralls.io/repos/containerbuildsystem/dockerfile-parse/badge.svg?branch=master
[coveralls status link]: https://coveralls.io/r/containerbuildsystem/dockerfile-parse?branch=master
[lgtm python badge]: https://img.shields.io/lgtm/grade/python/g/containerbuildsystem/dockerfile-parse.svg?logo=lgtm&logoWidth=18
[lgtm python link]: https://lgtm.com/projects/g/containerbuildsystem/dockerfile-parse/context:python
[lgtm alerts badge]: https://img.shields.io/lgtm/alerts/g/containerbuildsystem/dockerfile-parse.svg?logo=lgtm&logoWidth=18
[lgtm alerts link]: https://lgtm.com/projects/g/containerbuildsystem/dockerfile-parse/alerts
[linters status badge]: https://github.com/containerbuildsystem/dockerfile-parse/workflows/Linters/badge.svg?branch=master&event=push
[linters status link]: https://github.com/containerbuildsystem/dockerfile-parse/actions?query=event%3Apush+branch%3Amaster+workflow%3A%22Linters%22
[unittests status badge]: https://github.com/containerbuildsystem/dockerfile-parse/workflows/Unittests/badge.svg?branch=master&event=push
[unittests status link]: https://github.com/containerbuildsystem/dockerfile-parse/actions?query=event%3Apush+branch%3Amaster+workflow%3A%22Unittests%22