{"id":13563344,"url":"https://github.com/keilerkonzept/dockerfile-json","last_synced_at":"2025-07-24T20:11:28.262Z","repository":{"id":36817162,"uuid":"216348958","full_name":"keilerkonzept/dockerfile-json","owner":"keilerkonzept","description":"🐳 parse \u0026 print a Dockerfile as JSON, query (e.g. extract base images) using JSONPath.","archived":false,"fork":false,"pushed_at":"2024-10-30T23:33:00.000Z","size":2989,"stargazers_count":22,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-04T16:44:09.592Z","etag":null,"topics":["base-images","build-args","cli","docker","dockerfile","extract","golang","jq","json","jsonpath"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/keilerkonzept.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-20T11:11:26.000Z","updated_at":"2024-10-29T13:51:59.000Z","dependencies_parsed_at":"2023-12-09T03:50:33.249Z","dependency_job_id":"09aa2153-ca5c-40ca-aedc-d36768c1befa","html_url":"https://github.com/keilerkonzept/dockerfile-json","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keilerkonzept%2Fdockerfile-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keilerkonzept%2Fdockerfile-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keilerkonzept%2Fdockerfile-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keilerkonzept%2Fdockerfile-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/keilerkonzept","download_url":"https://codeload.github.com/keilerkonzept/dockerfile-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226084432,"owners_count":17571155,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["base-images","build-args","cli","docker","dockerfile","extract","golang","jq","json","jsonpath"],"created_at":"2024-08-01T13:01:18.094Z","updated_at":"2024-11-23T18:59:14.239Z","avatar_url":"https://github.com/keilerkonzept.png","language":"Go","funding_links":[],"categories":["Go","cli"],"sub_categories":[],"readme":"# dockerfile-json\n\nPrints Dockerfiles as JSON to stdout, optionally evaluates build args. Uses the [official Dockerfile parser](https://github.com/moby/buildkit/blob/master/frontend/dockerfile/) from buildkit. Plays well with `jq`.\n\n## Contents\n\n- [Contents](#contents)\n- [Get it](#get-it)\n- [Usage](#usage)\n- [Examples](#examples)\n  - [JSON output](#json-output)\n  - [Extract build stage names](#extract-build-stage-names)\n  - [Extract base images](#extract-base-images)\n    - [Expand build args, omit stage aliases and `scratch`](#expand-build-args-omit-stage-aliases-and-scratch)\n    - [Set build args, omit stage aliases and `scratch`](#set-build-args-omit-stage-aliases-and-scratch)\n    - [Expand build args, include all base names](#expand-build-args-include-all-base-names)\n    - [Ignore build args, include all base names](#ignore-build-args-include-all-base-names)\n\n## Get it\n\nUsing go get:\n\n```bash\ngo get -u github.com/keilerkonzept/dockerfile-json\n```\n\nOr [download the binary for your platform](https://github.com/keilerkonzept/dockerfile-json/releases/latest) from the releases page.\n\n## Usage\n\n### CLI\n\n```text\ndockerfile-json [PATHS...]\n\nUsage of dockerfile-json:\n  -build-arg value\n    \ta key/value pair KEY[=VALUE]\n  -expand-build-args\n    \texpand build args (default true)\n  -jsonpath string\n    \tselect parts of the output using JSONPath (https://goessner.net/articles/JsonPath)\n  -jsonpath-raw\n    \twhen using JSONPath, output raw strings, not JSON values\n  -quiet\n    \tsuppress log output (stderr)\n```\n\n## Examples\n\n### JSON output\n\n`Dockerfile`\n```Dockerfile\nARG ALPINE_TAG=3.10\n\nFROM alpine:${ALPINE_TAG} AS build\nRUN --network=host echo \"Hello world\" \u003e abc\n\nFROM build AS test\nRUN --security=insecure echo \"foo\" \u003e bar\n\nFROM scratch\nCOPY --from=build --chown=nobody:nobody abc .\nRUN --mount=type=bind,source=./abc,target=/def\nCMD [\"echo\"]\n```\n\n```sh\n$ dockerfile-json Dockerfile | jq .\n```\n```json\n{\n  \"MetaArgs\": [\n    {\n      \"Key\": \"ALPINE_TAG\",\n      \"DefaultValue\": \"3.10\",\n      \"ProvidedValue\": null,\n      \"Value\": \"3.10\"\n    }\n  ],\n  \"Stages\": [\n    {\n      \"Name\": \"build\",\n      \"OrigCmd\": \"FROM\",\n      \"BaseName\": \"alpine:3.10\",\n      \"Platform\": \"\",\n      \"Comment\": \"\",\n      \"SourceCode\": \"FROM alpine:${ALPINE_TAG} AS build\",\n      \"Location\": [\n        {\n          \"Start\": {\n            \"Line\": 3,\n            \"Character\": 0\n          },\n          \"End\": {\n            \"Line\": 3,\n            \"Character\": 0\n          }\n        }\n      ],\n      \"As\": \"build\",\n      \"From\": {\n        \"Image\": \"alpine:3.10\"\n      },\n      \"Commands\": [\n        {\n          \"CmdLine\": [\n            \"echo \\\"Hello world\\\" \u003e abc\"\n          ],\n          \"Files\": null,\n          \"FlagsUsed\": [\n            \"network\"\n          ],\n          \"Mounts\": [],\n          \"Name\": \"RUN\",\n          \"NetworkMode\": \"host\",\n          \"PrependShell\": true,\n          \"Security\": \"sandbox\"\n        }\n      ]\n    },\n    {\n      \"Name\": \"test\",\n      \"OrigCmd\": \"FROM\",\n      \"BaseName\": \"build\",\n      \"Platform\": \"\",\n      \"Comment\": \"\",\n      \"SourceCode\": \"FROM build AS test\",\n      \"Location\": [\n        {\n          \"Start\": {\n            \"Line\": 6,\n            \"Character\": 0\n          },\n          \"End\": {\n            \"Line\": 6,\n            \"Character\": 0\n          }\n        }\n      ],\n      \"As\": \"test\",\n      \"From\": {\n        \"Stage\": {\n          \"Named\": \"build\",\n          \"Index\": 0\n        }\n      },\n      \"Commands\": [\n        {\n          \"CmdLine\": [\n            \"echo \\\"foo\\\" \u003e bar\"\n          ],\n          \"Files\": null,\n          \"FlagsUsed\": [\n            \"security\"\n          ],\n          \"Mounts\": [],\n          \"Name\": \"RUN\",\n          \"NetworkMode\": \"default\",\n          \"PrependShell\": true,\n          \"Security\": \"insecure\"\n        }\n      ]\n    },\n    {\n      \"Name\": \"\",\n      \"OrigCmd\": \"FROM\",\n      \"BaseName\": \"scratch\",\n      \"Platform\": \"\",\n      \"Comment\": \"\",\n      \"SourceCode\": \"FROM scratch\",\n      \"Location\": [\n        {\n          \"Start\": {\n            \"Line\": 9,\n            \"Character\": 0\n          },\n          \"End\": {\n            \"Line\": 9,\n            \"Character\": 0\n          }\n        }\n      ],\n      \"From\": {\n        \"Scratch\": true\n      },\n      \"Commands\": [\n        {\n          \"Chmod\": \"\",\n          \"Chown\": \"nobody:nobody\",\n          \"DestPath\": \".\",\n          \"ExcludePatterns\": null,\n          \"From\": \"build\",\n          \"Link\": false,\n          \"Mounts\": null,\n          \"Name\": \"COPY\",\n          \"NetworkMode\": \"\",\n          \"Parents\": false,\n          \"Security\": \"\",\n          \"SourceContents\": null,\n          \"SourcePaths\": [\n            \"abc\"\n          ]\n        },\n        {\n          \"CmdLine\": [],\n          \"Files\": null,\n          \"FlagsUsed\": [\n            \"mount\"\n          ],\n          \"Mounts\": [\n            {\n              \"Type\": \"bind\",\n              \"From\": \"\",\n              \"Source\": \"\",\n              \"Target\": \"\",\n              \"ReadOnly\": true,\n              \"SizeLimit\": 0,\n              \"CacheID\": \"\",\n              \"CacheSharing\": \"\",\n              \"Required\": false,\n              \"Env\": null,\n              \"Mode\": null,\n              \"UID\": null,\n              \"GID\": null\n            }\n          ],\n          \"Name\": \"RUN\",\n          \"NetworkMode\": \"default\",\n          \"PrependShell\": true,\n          \"Security\": \"sandbox\"\n        },\n        {\n          \"CmdLine\": [\n            \"echo\"\n          ],\n          \"Files\": null,\n          \"Mounts\": null,\n          \"Name\": \"CMD\",\n          \"NetworkMode\": \"\",\n          \"PrependShell\": false,\n          \"Security\": \"\"\n        }\n      ]\n    }\n  ]\n}\n```\n\n### Extract build stage names\n\n`Dockerfile`\n```Dockerfile\nFROM maven:alpine AS build\n# ...\n\nFROM build AS test\n# ...\n\nFROM openjdk:jre-alpine\n# ...\n```\n\n```sh\n$ dockerfile-json --jsonpath=..As Dockerfile\n```\n```json\n\"build\"\n\"test\"\n```\n\n### Extract base images\n\n`Dockerfile`\n```Dockerfile\nARG ALPINE_TAG=3.10\nARG APP_BASE=scratch\n\nFROM alpine:$ALPINE_TAG AS build\n# ...\n\nFROM build\n# ...\n\nFROM $APP_BASE\n# ...\n```\n\n#### Expand build args, omit stage aliases and `scratch`\n\nUsing `jq`:\n```sh\n$ dockerfile-json Dockerfile |\n    jq '.Stages[] | select(.From | .Stage or .Scratch | not) | .BaseName'\n```\n```json\n\"alpine:3.10\"\n```\n\nUsing `--jsonpath`:\n```sh\n\n$ dockerfile-json --jsonpath=..Image Dockerfile\n```\n```json\n\"alpine:3.10\"\n```\n\nUsing `--jsonpath`, `--jsonpath-raw` output:\n```sh\n$ dockerfile-json --jsonpath=..Image --jsonpath-raw Dockerfile\n```\n```json\nalpine:3.10\n```\n\n#### Set build args, omit stage aliases and `scratch`\n\n```sh\n$ dockerfile-json --build-arg ALPINE_TAG=hello-world --jsonpath=..Image Dockerfile\n```\n```json\n\"alpine:hello-world\"\n```\n\n#### Expand build args, include all base names\n\n```sh\n$  dockerfile-json --jsonpath=..BaseName Dockerfile\n```\n```json\n\"alpine:3.10\"\n\"build\"\n\"scratch\"\n```\n\n#### Ignore build args, include all base names\n\n```sh\n$ dockerfile-json --expand-build-args=false --jsonpath=..BaseName Dockerfile\n```\n```json\n\"alpine:${ALPINE_TAG}\"\n\"build\"\n\"${APP_BASE}\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeilerkonzept%2Fdockerfile-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeilerkonzept%2Fdockerfile-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeilerkonzept%2Fdockerfile-json/lists"}