slimtoolkit/slim · error
bad instruction prefix
Error message
bad instruction prefix
What it means
ErrBadInstPrefix is returned by the dockerfile reverse-engineering package when a parsed instruction line does not start with a recognized Dockerfile instruction prefix. The reverse parser maps image history/lines back to Dockerfile instructions and cannot classify a line whose prefix it does not know. It signals unexpected or malformed line content rather than caller misuse.
Source
Thrown at pkg/docker/dockerfile/reverse/reverse.go:21
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"os"
"sort"
"strconv"
"strings"
"time"
"github.com/dustin/go-humanize"
docker "github.com/fsouza/go-dockerclient"
"github.com/google/shlex"
log "github.com/sirupsen/logrus"
)
var (
ErrBadInstPrefix = errors.New("bad instruction prefix")
)
// Dockerfile represents the reverse engineered Dockerfile info
type Dockerfile struct {
Lines []string `json:"lines,omitempty"`
Maintainers []string `json:"maintainers,omitempty"`
AllUsers []string `json:"all_users,omitempty"`
ExeUser string `json:"exe_user,omitempty"`
ExposedPorts []string `json:"exposed_ports,omitempty"`
ImageStack []*ImageInfo `json:"image_stack"`
AllInstructions []*InstructionInfo `json:"all_instructions"`
InstructionGroups [][]*InstructionInfo `json:"instruction_groups"`
InstructionGroupsReverse [][]*InstructionInfo `json:"instruction_groups_reverse"`
HasOnbuild bool `json:"has_onbuild"`
}
type ImageInfo struct {
IsTopImage bool `json:"is_top_image"`View on GitHub (pinned to 81940d17fa)
Solutions
- Inspect the source image's history (docker history --no-trunc) for lines with unexpected first tokens.
- Update slimtoolkit to a version whose reverse parser recognizes the instruction prefix in question.
- Skip or sanitize unrecognized history lines before passing them to the reverse package.
- If the line is a builder comment or metadata artifact, strip it prior to reverse engineering.
Defensive patterns
Strategy: try-catch
Validate before calling
firstToken := strings.Fields(line)[0]
known := map[string]bool{"FROM":true,"RUN":true,"CMD":true,"LABEL":true,"MAINTAINER":true,"EXPOSE":true,"ENV":true,"ADD":true,"COPY":true,"ENTRYPOINT":true,"VOLUME":true,"USER":true,"WORKDIR":true,"ARG":true,"ONBUILD":true,"STOPSIGNAL":true,"HEALTHCHECK":true,"SHELL":true}
if !known[strings.ToUpper(firstToken)] { /* skip or log line */ } Try / catch
df, err := reverse.FromImage(...)
if errors.Is(err, reverse.ErrBadInstPrefix) {
log.Warnf("skipping unrecognized instruction line: %v", err)
// proceed with partial result or sanitize input and retry
} Prevention
- Pre-trim history lines and skip comment/metadata lines.
- Keep the library updated to cover newer Docker instruction keywords.
- Audit image history with 'docker history --no-trunc' before reverse engineering.
- Log the offending line so the prefix table can be extended.
When it happens
Trigger: Reverse-engineering a Dockerfile from image history where a history line's first token is not a known instruction keyword (FROM, RUN, MAINTAINER, etc.).
Common situations: Images built by non-standard builders or with unusual metadata comments in history; older/newer Docker instruction keywords not covered by the reverse parser's prefix table.
Related errors
- when using JSON array syntax, arrays must be comprised of st
- unknown instruction
- only one escape parser directive can be used
- invalid Dockerfile
- invalid dockerfile reference - %s
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/6b6c653a34edd69d.
Report an issue: GitHub.