https://github.com/harehare/dockerfile.mq
A Dockerfile parser implemented as an mq module.
https://github.com/harehare/dockerfile.mq
dockerfile markdown mq
Last synced: 6 days ago
JSON representation
A Dockerfile parser implemented as an mq module.
- Host: GitHub
- URL: https://github.com/harehare/dockerfile.mq
- Owner: harehare
- Created: 2026-06-13T10:04:07.000Z (11 days ago)
- Default Branch: main
- Last Pushed: 2026-06-13T10:07:38.000Z (11 days ago)
- Last Synced: 2026-06-13T12:09:54.263Z (11 days ago)
- Topics: dockerfile, markdown, mq
- Homepage: https://mqlang.org
- Size: 5.86 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
dockerfile.mq
A Dockerfile parser implemented as an [mq](https://github.com/harehare/mq) module.
## Features
- Parse all standard Dockerfile instructions
- Multi-stage build support (`FROM ... AS`)
- Line continuation (`\`) handling
- Convenience helpers: `dockerfile_stages`, `dockerfile_ports`, `dockerfile_env`
## Supported Instructions
`FROM` `RUN` `CMD` `LABEL` `EXPOSE` `ENV` `ADD` `COPY` `ENTRYPOINT` `VOLUME` `USER` `WORKDIR` `ARG` `ONBUILD` `STOPSIGNAL` `HEALTHCHECK` `SHELL`
## Installation
```sh
cp dockerfile.mq ~/.local/mq/config/
```
### HTTP Import
```sh
mq -I raw 'import "github.com/harehare/dockerfile.mq" | dockerfile::dockerfile_parse(.)' Dockerfile
```
## API
| Function | Description |
|---|---|
| `dockerfile_parse(input)` | Parse a Dockerfile and return an array of instruction dicts |
| `dockerfile_stringify(instructions)` | Serialize an array of instruction dicts back to a Dockerfile string |
| `dockerfile_stages(input)` | Return all `FROM` instructions (multi-stage) |
| `dockerfile_ports(input)` | Return all exposed ports as a flat string array |
| `dockerfile_env(input)` | Return all `ENV` instructions as a dict |
## Example
Given `Dockerfile`:
```dockerfile
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:20-alpine
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app/dist ./dist
EXPOSE 3000
CMD ["node", "dist/index.js"]
```
```sh
# List all stages (multi-stage build)
mq -I raw 'import "dockerfile" | dockerfile::dockerfile_stages(.) | map(fn(s): s["image"] + " AS " + s["alias"];)' Dockerfile
# => ["node:20-alpine AS builder", "node:20-alpine AS None"]
# Get exposed ports
mq -I raw 'import "dockerfile" | dockerfile::dockerfile_ports(.)' Dockerfile
# => ["3000"]
# Get environment variables
mq -I raw 'import "dockerfile" | dockerfile::dockerfile_env(.)' Dockerfile
# => {"NODE_ENV": "production"}
# List all RUN commands
mq -I raw 'import "dockerfile" | dockerfile::dockerfile_parse(.) | filter(fn(i): i["instruction"] == "RUN";) | map(fn(i): i["args"];)' Dockerfile
# => ["npm ci", "npm run build"]
# Check base image
mq -I raw 'import "dockerfile" | dockerfile::dockerfile_stages(.) | first() | ."image"' Dockerfile
# => "node:20-alpine"
# Round-trip: parse then stringify back to Dockerfile text
mq -I raw 'import "dockerfile" | dockerfile::dockerfile_stringify(dockerfile::dockerfile_parse(.))' Dockerfile
# Modify an instruction and serialize (e.g. bump the base image tag)
mq -I raw 'import "dockerfile" | let instrs = dockerfile::dockerfile_parse(.) | dockerfile::dockerfile_stringify(map(instrs, fn(i): if (i["instruction"] == "FROM"): set(i, "image", "node:22-alpine") else: i;))' Dockerfile
```
## License
MIT